From 3c622ae3ce1f22cc3fc4d1968e7c4373a2381b3a Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Thu, 2 Nov 2023 17:16:34 +0000 Subject: [PATCH] [smithy-rs] Delete `aws_smithy_http::ResolveEndpoint` and point usages to service-specific trait (#3078) ## Motivation and Context - Fixes https://github.com/awslabs/smithy-rs/issues/3043 As a follow up to #3072 this removes the old endpoint resolver interfaces in favor of creating a per-service resolver trait. This trait defines a `into_shared_resolver()` method which converts the local trait into a global resolver that can be used with the orchestrator. ## Description ## Testing ## Checklist - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- sdk/accessanalyzer/src/config.rs | 70 +- sdk/accessanalyzer/src/config/endpoint.rs | 143 ++-- sdk/account/src/config.rs | 70 +- sdk/account/src/config/endpoint.rs | 117 +-- sdk/acm/src/config.rs | 70 +- sdk/acm/src/config/endpoint.rs | 142 ++-- sdk/acmpca/src/config.rs | 70 +- sdk/acmpca/src/config/endpoint.rs | 142 ++-- sdk/alexaforbusiness/src/config.rs | 70 +- sdk/alexaforbusiness/src/config/endpoint.rs | 115 +-- sdk/amp/src/config.rs | 70 +- sdk/amp/src/config/endpoint.rs | 124 +-- sdk/amplify/src/config.rs | 70 +- sdk/amplify/src/config/endpoint.rs | 133 ++-- sdk/amplifybackend/src/config.rs | 70 +- sdk/amplifybackend/src/config/endpoint.rs | 131 ++-- sdk/amplifyuibuilder/src/config.rs | 70 +- sdk/amplifyuibuilder/src/config/endpoint.rs | 131 ++-- sdk/apigateway/src/config.rs | 70 +- sdk/apigateway/src/config/endpoint.rs | 137 ++-- sdk/apigatewaymanagement/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/apigatewayv2/src/config.rs | 70 +- sdk/apigatewayv2/src/config/endpoint.rs | 137 ++-- sdk/appconfig/src/config.rs | 70 +- sdk/appconfig/src/config/endpoint.rs | 140 ++-- sdk/appconfigdata/src/config.rs | 70 +- sdk/appconfigdata/src/config/endpoint.rs | 138 ++-- sdk/appfabric/src/config.rs | 70 +- sdk/appfabric/src/config/endpoint.rs | 115 +-- sdk/appflow/src/config.rs | 70 +- sdk/appflow/src/config/endpoint.rs | 130 ++-- sdk/appintegrations/src/config.rs | 70 +- sdk/appintegrations/src/config/endpoint.rs | 124 +-- sdk/applicationautoscaling/src/config.rs | 70 +- .../src/config/endpoint.rs | 140 ++-- sdk/applicationcostprofiler/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/applicationdiscovery/src/config.rs | 70 +- .../src/config/endpoint.rs | 121 +-- sdk/applicationinsights/src/config.rs | 70 +- .../src/config/endpoint.rs | 137 ++-- sdk/appmesh/src/config.rs | 70 +- sdk/appmesh/src/config/endpoint.rs | 155 ++-- sdk/apprunner/src/config.rs | 70 +- sdk/apprunner/src/config/endpoint.rs | 121 +-- sdk/appstream/src/config.rs | 70 +- sdk/appstream/src/config/endpoint.rs | 129 ++-- sdk/appsync/src/config.rs | 70 +- sdk/appsync/src/config/endpoint.rs | 135 ++-- sdk/arczonalshift/src/config.rs | 70 +- sdk/arczonalshift/src/config/endpoint.rs | 115 +-- sdk/athena/src/config.rs | 70 +- sdk/athena/src/config/endpoint.rs | 141 ++-- sdk/auditmanager/src/config.rs | 70 +- sdk/auditmanager/src/config/endpoint.rs | 126 +-- sdk/autoscaling/src/config.rs | 70 +- sdk/autoscaling/src/config/endpoint.rs | 139 ++-- sdk/autoscalingplans/src/config.rs | 70 +- sdk/autoscalingplans/src/config/endpoint.rs | 138 ++-- sdk/aws-smithy-http/src/endpoint.rs | 275 +------ .../src/client/orchestrator/endpoints.rs | 47 +- sdk/backup/src/config.rs | 70 +- sdk/backup/src/config/endpoint.rs | 138 ++-- sdk/backupgateway/src/config.rs | 70 +- sdk/backupgateway/src/config/endpoint.rs | 136 ++-- sdk/backupstorage/src/config.rs | 70 +- sdk/backupstorage/src/config/endpoint.rs | 115 +-- sdk/batch/src/config.rs | 70 +- sdk/batch/src/config/endpoint.rs | 142 ++-- sdk/bedrock/src/config.rs | 70 +- sdk/bedrock/src/config/endpoint.rs | 115 +-- sdk/bedrockruntime/Cargo.toml | 4 - sdk/bedrockruntime/src/config.rs | 70 +- sdk/bedrockruntime/src/config/endpoint.rs | 115 +-- sdk/billingconductor/src/config.rs | 70 +- sdk/billingconductor/src/config/endpoint.rs | 116 +-- sdk/braket/src/config.rs | 70 +- sdk/braket/src/config/endpoint.rs | 118 +-- sdk/budgets/src/config.rs | 70 +- sdk/budgets/src/config/endpoint.rs | 117 +-- sdk/chime/src/config.rs | 70 +- sdk/chime/src/config/endpoint.rs | 116 +-- sdk/chimesdkidentity/src/config.rs | 70 +- sdk/chimesdkidentity/src/config/endpoint.rs | 116 +-- sdk/chimesdkmediapipelines/src/config.rs | 70 +- .../src/config/endpoint.rs | 119 +-- sdk/chimesdkmeetings/src/config.rs | 70 +- sdk/chimesdkmeetings/src/config/endpoint.rs | 121 +-- sdk/chimesdkmessaging/src/config.rs | 70 +- sdk/chimesdkmessaging/src/config/endpoint.rs | 116 +-- sdk/chimesdkvoice/src/config.rs | 70 +- sdk/chimesdkvoice/src/config/endpoint.rs | 115 +-- sdk/cleanrooms/src/config.rs | 70 +- sdk/cleanrooms/src/config/endpoint.rs | 115 +-- sdk/cloud9/src/config.rs | 70 +- sdk/cloud9/src/config/endpoint.rs | 135 ++-- sdk/cloudcontrol/src/config.rs | 70 +- sdk/cloudcontrol/src/config/endpoint.rs | 143 ++-- sdk/clouddirectory/src/config.rs | 70 +- sdk/clouddirectory/src/config/endpoint.rs | 125 +-- sdk/cloudformation/src/config.rs | 70 +- sdk/cloudformation/src/config/endpoint.rs | 143 ++-- sdk/cloudfront/src/config.rs | 70 +- sdk/cloudfront/src/config/endpoint.rs | 118 +-- sdk/cloudhsm/src/config.rs | 70 +- sdk/cloudhsm/src/config/endpoint.rs | 116 +-- sdk/cloudhsmv2/src/config.rs | 70 +- sdk/cloudhsmv2/src/config/endpoint.rs | 136 ++-- sdk/cloudsearch/src/config.rs | 70 +- sdk/cloudsearch/src/config/endpoint.rs | 124 +-- sdk/cloudsearchdomain/src/config.rs | 70 +- sdk/cloudsearchdomain/src/config/endpoint.rs | 115 +-- sdk/cloudtrail/src/config.rs | 70 +- sdk/cloudtrail/src/config/endpoint.rs | 143 ++-- sdk/cloudtraildata/src/config.rs | 70 +- sdk/cloudtraildata/src/config/endpoint.rs | 115 +-- sdk/cloudwatch/src/config.rs | 70 +- sdk/cloudwatch/src/config/endpoint.rs | 143 ++-- sdk/cloudwatchevents/src/config.rs | 70 +- sdk/cloudwatchevents/src/config/endpoint.rs | 143 ++-- sdk/cloudwatchlogs/src/config.rs | 70 +- sdk/cloudwatchlogs/src/config/endpoint.rs | 143 ++-- sdk/codeartifact/src/config.rs | 70 +- sdk/codeartifact/src/config/endpoint.rs | 127 ++-- sdk/codebuild/src/config.rs | 70 +- sdk/codebuild/src/config/endpoint.rs | 142 ++-- sdk/codecatalyst/src/config.rs | 70 +- sdk/codecatalyst/src/config/endpoint.rs | 99 ++- sdk/codecommit/src/config.rs | 70 +- sdk/codecommit/src/config/endpoint.rs | 142 ++-- sdk/codedeploy/src/config.rs | 70 +- sdk/codedeploy/src/config/endpoint.rs | 143 ++-- sdk/codeguruprofiler/src/config.rs | 70 +- sdk/codeguruprofiler/src/config/endpoint.rs | 115 +-- sdk/codegurureviewer/src/config.rs | 70 +- sdk/codegurureviewer/src/config/endpoint.rs | 124 +-- sdk/codegurusecurity/src/config.rs | 70 +- sdk/codegurusecurity/src/config/endpoint.rs | 115 +-- sdk/codepipeline/src/config.rs | 70 +- sdk/codepipeline/src/config/endpoint.rs | 139 ++-- sdk/codestar/src/config.rs | 70 +- sdk/codestar/src/config/endpoint.rs | 127 ++-- sdk/codestarconnections/src/config.rs | 70 +- .../src/config/endpoint.rs | 130 ++-- sdk/codestarnotifications/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/cognitoidentity/src/config.rs | 70 +- sdk/cognitoidentity/src/config/endpoint.rs | 135 ++-- sdk/cognitoidentityprovider/src/config.rs | 70 +- .../src/config/endpoint.rs | 136 ++-- sdk/cognitosync/src/config.rs | 70 +- sdk/cognitosync/src/config/endpoint.rs | 125 +-- sdk/comprehend/src/config.rs | 70 +- sdk/comprehend/src/config/endpoint.rs | 130 ++-- sdk/comprehendmedical/src/config.rs | 70 +- sdk/comprehendmedical/src/config/endpoint.rs | 125 +-- sdk/computeoptimizer/src/config.rs | 70 +- sdk/computeoptimizer/src/config/endpoint.rs | 131 ++-- sdk/config/src/config.rs | 70 +- sdk/config/src/config/endpoint.rs | 143 ++-- sdk/connect/src/config.rs | 70 +- sdk/connect/src/config/endpoint.rs | 126 +-- sdk/connectcampaigns/src/config.rs | 70 +- sdk/connectcampaigns/src/config/endpoint.rs | 118 +-- sdk/connectcases/src/config.rs | 70 +- sdk/connectcases/src/config/endpoint.rs | 115 +-- sdk/connectcontactlens/src/config.rs | 70 +- sdk/connectcontactlens/src/config/endpoint.rs | 122 +-- sdk/connectparticipant/src/config.rs | 70 +- sdk/connectparticipant/src/config/endpoint.rs | 117 +-- sdk/controltower/src/config.rs | 70 +- sdk/controltower/src/config/endpoint.rs | 132 ++-- sdk/costandusagereport/src/config.rs | 70 +- sdk/costandusagereport/src/config/endpoint.rs | 116 +-- sdk/costexplorer/src/config.rs | 70 +- sdk/costexplorer/src/config/endpoint.rs | 117 +-- sdk/customerprofiles/src/config.rs | 70 +- sdk/customerprofiles/src/config/endpoint.rs | 124 +-- sdk/databasemigration/src/config.rs | 70 +- sdk/databasemigration/src/config/endpoint.rs | 144 ++-- sdk/databrew/src/config.rs | 70 +- sdk/databrew/src/config/endpoint.rs | 136 ++-- sdk/dataexchange/src/config.rs | 70 +- sdk/dataexchange/src/config/endpoint.rs | 125 +-- sdk/datapipeline/src/config.rs | 70 +- sdk/datapipeline/src/config/endpoint.rs | 119 +-- sdk/datasync/src/config.rs | 70 +- sdk/datasync/src/config/endpoint.rs | 142 ++-- sdk/datazone/src/config.rs | 70 +- sdk/datazone/src/config/endpoint.rs | 100 ++- sdk/dax/src/config.rs | 70 +- sdk/dax/src/config/endpoint.rs | 128 ++-- sdk/detective/src/config.rs | 70 +- sdk/detective/src/config/endpoint.rs | 139 ++-- sdk/devicefarm/src/config.rs | 70 +- sdk/devicefarm/src/config/endpoint.rs | 116 +-- sdk/devopsguru/src/config.rs | 70 +- sdk/devopsguru/src/config/endpoint.rs | 125 +-- sdk/directconnect/src/config.rs | 70 +- sdk/directconnect/src/config/endpoint.rs | 142 ++-- sdk/directory/src/config.rs | 70 +- sdk/directory/src/config/endpoint.rs | 142 ++-- sdk/dlm/src/config.rs | 70 +- sdk/dlm/src/config/endpoint.rs | 139 ++-- sdk/docdb/src/config.rs | 70 +- sdk/docdb/src/config/endpoint.rs | 144 ++-- sdk/docdbelastic/src/config.rs | 70 +- sdk/docdbelastic/src/config/endpoint.rs | 115 +-- sdk/drs/src/config.rs | 70 +- sdk/drs/src/config/endpoint.rs | 135 ++-- sdk/dynamodb/src/config.rs | 70 +- sdk/dynamodb/src/config/endpoint.rs | 145 ++-- sdk/dynamodbstreams/src/config.rs | 70 +- sdk/dynamodbstreams/src/config/endpoint.rs | 140 ++-- sdk/ebs/src/config.rs | 70 +- sdk/ebs/src/config/endpoint.rs | 142 ++-- sdk/ec2/src/config.rs | 70 +- sdk/ec2/src/config/endpoint.rs | 148 ++-- sdk/ec2instanceconnect/src/config.rs | 70 +- sdk/ec2instanceconnect/src/config/endpoint.rs | 115 +-- sdk/ecr/src/config.rs | 70 +- sdk/ecr/src/config/endpoint.rs | 143 ++-- sdk/ecrpublic/src/config.rs | 70 +- sdk/ecrpublic/src/config/endpoint.rs | 115 +-- sdk/ecs/src/config.rs | 70 +- sdk/ecs/src/config/endpoint.rs | 143 ++-- sdk/efs/src/config.rs | 70 +- sdk/efs/src/config/endpoint.rs | 161 ++-- sdk/eks/src/config.rs | 70 +- sdk/eks/src/config/endpoint.rs | 142 ++-- sdk/elasticache/src/config.rs | 70 +- sdk/elasticache/src/config/endpoint.rs | 143 ++-- sdk/elasticbeanstalk/src/config.rs | 70 +- sdk/elasticbeanstalk/src/config/endpoint.rs | 142 ++-- sdk/elasticinference/src/config.rs | 70 +- sdk/elasticinference/src/config/endpoint.rs | 120 +-- sdk/elasticloadbalancing/src/config.rs | 70 +- .../src/config/endpoint.rs | 143 ++-- sdk/elasticloadbalancingv2/src/config.rs | 70 +- .../src/config/endpoint.rs | 143 ++-- sdk/elasticsearch/src/config.rs | 70 +- sdk/elasticsearch/src/config/endpoint.rs | 143 ++-- sdk/elastictranscoder/src/config.rs | 70 +- sdk/elastictranscoder/src/config/endpoint.rs | 122 +-- sdk/emr/src/config.rs | 70 +- sdk/emr/src/config/endpoint.rs | 144 ++-- sdk/emrcontainers/src/config.rs | 70 +- sdk/emrcontainers/src/config/endpoint.rs | 135 ++-- sdk/emrserverless/src/config.rs | 70 +- sdk/emrserverless/src/config/endpoint.rs | 119 +-- sdk/entityresolution/src/config.rs | 70 +- sdk/entityresolution/src/config/endpoint.rs | 115 +-- sdk/eventbridge/src/config.rs | 70 +- sdk/eventbridge/src/config/endpoint.rs | 151 ++-- sdk/evidently/src/config.rs | 70 +- sdk/evidently/src/config/endpoint.rs | 123 +-- sdk/finspace/src/config.rs | 70 +- sdk/finspace/src/config/endpoint.rs | 119 +-- sdk/finspacedata/src/config.rs | 70 +- sdk/finspacedata/src/config/endpoint.rs | 119 +-- sdk/firehose/src/config.rs | 70 +- sdk/firehose/src/config/endpoint.rs | 142 ++-- sdk/fis/src/config.rs | 70 +- sdk/fis/src/config/endpoint.rs | 117 +-- sdk/fms/src/config.rs | 70 +- sdk/fms/src/config/endpoint.rs | 156 ++-- sdk/forecast/src/config.rs | 70 +- sdk/forecast/src/config/endpoint.rs | 126 +-- sdk/forecastquery/src/config.rs | 70 +- sdk/forecastquery/src/config/endpoint.rs | 126 +-- sdk/frauddetector/src/config.rs | 70 +- sdk/frauddetector/src/config/endpoint.rs | 120 +-- sdk/fsx/src/config.rs | 70 +- sdk/fsx/src/config/endpoint.rs | 142 ++-- sdk/gamelift/src/config.rs | 70 +- sdk/gamelift/src/config/endpoint.rs | 136 ++-- sdk/glacier/src/config.rs | 70 +- sdk/glacier/src/config/endpoint.rs | 144 ++-- sdk/glacier/src/operation/upload_archive.rs | 16 +- .../src/operation/upload_multipart_part.rs | 4 +- sdk/globalaccelerator/src/config.rs | 70 +- sdk/globalaccelerator/src/config/endpoint.rs | 115 +-- sdk/glue/src/config.rs | 70 +- sdk/glue/src/config/endpoint.rs | 141 ++-- sdk/grafana/src/config.rs | 70 +- sdk/grafana/src/config/endpoint.rs | 124 +-- sdk/greengrass/src/config.rs | 70 +- sdk/greengrass/src/config/endpoint.rs | 130 ++-- sdk/greengrassv2/src/config.rs | 70 +- sdk/greengrassv2/src/config/endpoint.rs | 130 ++-- sdk/groundstation/src/config.rs | 70 +- sdk/groundstation/src/config/endpoint.rs | 127 ++-- sdk/guardduty/src/config.rs | 70 +- sdk/guardduty/src/config/endpoint.rs | 142 ++-- sdk/health/src/config.rs | 70 +- sdk/health/src/config/endpoint.rs | 117 +-- sdk/healthlake/src/config.rs | 70 +- sdk/healthlake/src/config/endpoint.rs | 117 +-- sdk/honeycode/src/config.rs | 70 +- sdk/honeycode/src/config/endpoint.rs | 116 +-- sdk/iam/src/config.rs | 70 +- sdk/iam/src/config/endpoint.rs | 122 +-- sdk/identitystore/src/config.rs | 70 +- sdk/identitystore/src/config/endpoint.rs | 129 ++-- sdk/imagebuilder/src/config.rs | 70 +- sdk/imagebuilder/src/config/endpoint.rs | 117 +-- sdk/inspector/src/config.rs | 70 +- sdk/inspector/src/config/endpoint.rs | 131 ++-- sdk/inspector2/src/config.rs | 70 +- sdk/inspector2/src/config/endpoint.rs | 133 ++-- sdk/internetmonitor/src/config.rs | 70 +- sdk/internetmonitor/src/config/endpoint.rs | 115 +-- sdk/iot/src/config.rs | 70 +- sdk/iot/src/config/endpoint.rs | 139 ++-- sdk/iot1clickdevices/src/config.rs | 70 +- sdk/iot1clickdevices/src/config/endpoint.rs | 115 +-- sdk/iot1clickprojects/src/config.rs | 70 +- sdk/iot1clickprojects/src/config/endpoint.rs | 121 +-- sdk/iotanalytics/src/config.rs | 70 +- sdk/iotanalytics/src/config/endpoint.rs | 122 +-- sdk/iotdataplane/src/config.rs | 70 +- sdk/iotdataplane/src/config/endpoint.rs | 139 ++-- sdk/iotdeviceadvisor/src/config.rs | 70 +- sdk/iotdeviceadvisor/src/config/endpoint.rs | 118 +-- sdk/iotevents/src/config.rs | 70 +- sdk/iotevents/src/config/endpoint.rs | 127 ++-- sdk/ioteventsdata/src/config.rs | 70 +- sdk/ioteventsdata/src/config/endpoint.rs | 115 +-- sdk/iotfleethub/src/config.rs | 70 +- sdk/iotfleethub/src/config/endpoint.rs | 130 ++-- sdk/iotfleetwise/src/config.rs | 70 +- sdk/iotfleetwise/src/config/endpoint.rs | 116 +-- sdk/iotjobsdataplane/src/config.rs | 70 +- sdk/iotjobsdataplane/src/config/endpoint.rs | 139 ++-- sdk/iotroborunner/src/config.rs | 70 +- sdk/iotroborunner/src/config/endpoint.rs | 115 +-- sdk/iotsecuretunneling/src/config.rs | 70 +- sdk/iotsecuretunneling/src/config/endpoint.rs | 139 ++-- sdk/iotsitewise/src/config.rs | 70 +- sdk/iotsitewise/src/config/endpoint.rs | 130 ++-- sdk/iotthingsgraph/src/config.rs | 70 +- sdk/iotthingsgraph/src/config/endpoint.rs | 120 +-- sdk/iottwinmaker/src/config.rs | 70 +- sdk/iottwinmaker/src/config/endpoint.rs | 120 +-- sdk/iotwireless/src/config.rs | 70 +- sdk/iotwireless/src/config/endpoint.rs | 119 +-- sdk/ivs/src/config.rs | 70 +- sdk/ivs/src/config/endpoint.rs | 121 +-- sdk/ivschat/src/config.rs | 70 +- sdk/ivschat/src/config/endpoint.rs | 117 +-- sdk/ivsrealtime/src/config.rs | 70 +- sdk/ivsrealtime/src/config/endpoint.rs | 115 +-- sdk/kafka/src/config.rs | 70 +- sdk/kafka/src/config/endpoint.rs | 138 ++-- sdk/kafkaconnect/src/config.rs | 70 +- sdk/kafkaconnect/src/config/endpoint.rs | 130 ++-- sdk/kendra/src/config.rs | 70 +- sdk/kendra/src/config/endpoint.rs | 125 +-- sdk/kendraranking/src/config.rs | 70 +- sdk/kendraranking/src/config/endpoint.rs | 100 ++- sdk/keyspaces/src/config.rs | 70 +- sdk/keyspaces/src/config/endpoint.rs | 135 ++-- sdk/kinesis/src/config.rs | 70 +- sdk/kinesis/src/config/endpoint.rs | 199 ++--- sdk/kinesisanalytics/src/config.rs | 70 +- sdk/kinesisanalytics/src/config/endpoint.rs | 137 ++-- sdk/kinesisanalyticsv2/src/config.rs | 70 +- sdk/kinesisanalyticsv2/src/config/endpoint.rs | 137 ++-- sdk/kinesisvideo/src/config.rs | 70 +- sdk/kinesisvideo/src/config/endpoint.rs | 130 ++-- sdk/kinesisvideoarchivedmedia/src/config.rs | 70 +- .../src/config/endpoint.rs | 130 ++-- sdk/kinesisvideomedia/src/config.rs | 70 +- sdk/kinesisvideomedia/src/config/endpoint.rs | 130 ++-- sdk/kinesisvideosignaling/src/config.rs | 70 +- .../src/config/endpoint.rs | 130 ++-- sdk/kinesisvideowebrtcstorage/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/kms/src/config.rs | 70 +- sdk/kms/src/config/endpoint.rs | 162 ++-- sdk/lakeformation/src/config.rs | 70 +- sdk/lakeformation/src/config/endpoint.rs | 141 ++-- sdk/lambda/src/config.rs | 70 +- sdk/lambda/src/config/endpoint.rs | 165 ++-- sdk/lexmodelbuilding/src/config.rs | 70 +- sdk/lexmodelbuilding/src/config/endpoint.rs | 125 +-- sdk/lexmodelsv2/src/config.rs | 70 +- sdk/lexmodelsv2/src/config/endpoint.rs | 125 +-- sdk/lexruntime/src/config.rs | 70 +- sdk/lexruntime/src/config/endpoint.rs | 125 +-- sdk/lexruntimev2/src/config.rs | 70 +- sdk/lexruntimev2/src/config/endpoint.rs | 125 +-- sdk/licensemanager/src/config.rs | 70 +- sdk/licensemanager/src/config/endpoint.rs | 142 ++-- .../src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- .../src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/lightsail/src/config.rs | 70 +- sdk/lightsail/src/config/endpoint.rs | 128 ++-- sdk/location/src/config.rs | 70 +- sdk/location/src/config/endpoint.rs | 115 +-- sdk/lookoutequipment/src/config.rs | 70 +- sdk/lookoutequipment/src/config/endpoint.rs | 117 +-- sdk/lookoutmetrics/src/config.rs | 70 +- sdk/lookoutmetrics/src/config/endpoint.rs | 123 +-- sdk/lookoutvision/src/config.rs | 70 +- sdk/lookoutvision/src/config/endpoint.rs | 121 +-- sdk/m2/src/config.rs | 70 +- sdk/m2/src/config/endpoint.rs | 121 +-- sdk/machinelearning/src/config.rs | 70 +- sdk/machinelearning/src/config/endpoint.rs | 116 +-- sdk/macie/src/config.rs | 70 +- sdk/macie/src/config/endpoint.rs | 117 +-- sdk/macie2/src/config.rs | 70 +- sdk/macie2/src/config/endpoint.rs | 138 ++-- sdk/managedblockchain/src/config.rs | 70 +- sdk/managedblockchain/src/config/endpoint.rs | 120 +-- sdk/managedblockchainquery/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/marketplacecatalog/src/config.rs | 70 +- sdk/marketplacecatalog/src/config/endpoint.rs | 115 +-- .../src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/marketplaceentitlement/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/marketplacemetering/src/config.rs | 70 +- .../src/config/endpoint.rs | 137 ++-- sdk/mediaconnect/src/config.rs | 70 +- sdk/mediaconnect/src/config/endpoint.rs | 130 ++-- sdk/mediaconvert/src/config.rs | 70 +- sdk/mediaconvert/src/config/endpoint.rs | 137 ++-- sdk/medialive/src/config.rs | 70 +- sdk/medialive/src/config/endpoint.rs | 130 ++-- sdk/mediapackage/src/config.rs | 70 +- sdk/mediapackage/src/config/endpoint.rs | 129 ++-- sdk/mediapackagev2/src/config.rs | 70 +- sdk/mediapackagev2/src/config/endpoint.rs | 115 +-- sdk/mediapackagevod/src/config.rs | 70 +- sdk/mediapackagevod/src/config/endpoint.rs | 129 ++-- sdk/mediastore/src/config.rs | 70 +- sdk/mediastore/src/config/endpoint.rs | 123 +-- sdk/mediastoredata/src/config.rs | 70 +- sdk/mediastoredata/src/config/endpoint.rs | 123 +-- sdk/mediatailor/src/config.rs | 70 +- sdk/mediatailor/src/config/endpoint.rs | 121 +-- sdk/medicalimaging/src/config.rs | 70 +- sdk/medicalimaging/src/config/endpoint.rs | 115 +-- sdk/memorydb/src/config.rs | 70 +- sdk/memorydb/src/config/endpoint.rs | 132 ++-- sdk/mgn/src/config.rs | 70 +- sdk/mgn/src/config/endpoint.rs | 135 ++-- sdk/migrationhub/src/config.rs | 70 +- sdk/migrationhub/src/config/endpoint.rs | 121 +-- sdk/migrationhubconfig/src/config.rs | 70 +- sdk/migrationhubconfig/src/config/endpoint.rs | 115 +-- sdk/migrationhuborchestrator/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/migrationhubrefactorspaces/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/migrationhubstrategy/src/config.rs | 70 +- .../src/config/endpoint.rs | 121 +-- sdk/mobile/src/config.rs | 70 +- sdk/mobile/src/config/endpoint.rs | 115 +-- sdk/mq/src/config.rs | 70 +- sdk/mq/src/config/endpoint.rs | 142 ++-- sdk/mturk/src/config.rs | 70 +- sdk/mturk/src/config/endpoint.rs | 116 +-- sdk/mwaa/src/config.rs | 70 +- sdk/mwaa/src/config/endpoint.rs | 129 ++-- sdk/neptune/src/config.rs | 70 +- sdk/neptune/src/config/endpoint.rs | 144 ++-- sdk/neptunedata/src/config.rs | 70 +- sdk/neptunedata/src/config/endpoint.rs | 115 +-- sdk/networkfirewall/src/config.rs | 70 +- sdk/networkfirewall/src/config/endpoint.rs | 141 ++-- sdk/networkmanager/src/config.rs | 70 +- sdk/networkmanager/src/config/endpoint.rs | 117 +-- sdk/nimble/src/config.rs | 70 +- sdk/nimble/src/config/endpoint.rs | 120 +-- sdk/oam/src/config.rs | 70 +- sdk/oam/src/config/endpoint.rs | 115 +-- sdk/omics/src/config.rs | 70 +- sdk/omics/src/config/endpoint.rs | 115 +-- sdk/opensearch/src/config.rs | 70 +- sdk/opensearch/src/config/endpoint.rs | 143 ++-- sdk/opensearchserverless/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/opsworks/src/config.rs | 70 +- sdk/opsworks/src/config/endpoint.rs | 129 ++-- sdk/opsworkscm/src/config.rs | 70 +- sdk/opsworkscm/src/config/endpoint.rs | 123 +-- sdk/organizations/src/config.rs | 70 +- sdk/organizations/src/config/endpoint.rs | 120 +-- sdk/osis/src/config.rs | 70 +- sdk/osis/src/config/endpoint.rs | 115 +-- sdk/outposts/src/config.rs | 70 +- sdk/outposts/src/config/endpoint.rs | 141 ++-- sdk/panorama/src/config.rs | 70 +- sdk/panorama/src/config/endpoint.rs | 115 +-- sdk/paymentcryptography/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/paymentcryptographydata/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/pcaconnectorad/src/config.rs | 70 +- sdk/pcaconnectorad/src/config/endpoint.rs | 115 +-- sdk/personalize/src/config.rs | 70 +- sdk/personalize/src/config/endpoint.rs | 125 +-- sdk/personalizeevents/src/config.rs | 70 +- sdk/personalizeevents/src/config/endpoint.rs | 115 +-- sdk/personalizeruntime/src/config.rs | 70 +- sdk/personalizeruntime/src/config/endpoint.rs | 115 +-- sdk/pi/src/config.rs | 70 +- sdk/pi/src/config/endpoint.rs | 136 ++-- sdk/pinpoint/src/config.rs | 70 +- sdk/pinpoint/src/config/endpoint.rs | 128 ++-- sdk/pinpointemail/src/config.rs | 70 +- sdk/pinpointemail/src/config/endpoint.rs | 137 ++-- sdk/pinpointsmsvoice/src/config.rs | 70 +- sdk/pinpointsmsvoice/src/config/endpoint.rs | 115 +-- sdk/pinpointsmsvoicev2/src/config.rs | 70 +- sdk/pinpointsmsvoicev2/src/config/endpoint.rs | 125 +-- sdk/pipes/src/config.rs | 70 +- sdk/pipes/src/config/endpoint.rs | 115 +-- sdk/polly/src/config.rs | 70 +- sdk/polly/src/config/endpoint.rs | 139 ++-- sdk/pricing/src/config.rs | 70 +- sdk/pricing/src/config/endpoint.rs | 116 +-- sdk/privatenetworks/src/config.rs | 70 +- sdk/privatenetworks/src/config/endpoint.rs | 115 +-- sdk/proton/src/config.rs | 70 +- sdk/proton/src/config/endpoint.rs | 119 +-- sdk/qldb/src/config.rs | 70 +- sdk/qldb/src/config/endpoint.rs | 128 ++-- sdk/qldbsession/src/config.rs | 70 +- sdk/qldbsession/src/config/endpoint.rs | 127 ++-- sdk/quicksight/src/config.rs | 70 +- sdk/quicksight/src/config/endpoint.rs | 130 ++-- sdk/ram/src/config.rs | 70 +- sdk/ram/src/config/endpoint.rs | 143 ++-- sdk/rbin/src/config.rs | 70 +- sdk/rbin/src/config/endpoint.rs | 135 ++-- sdk/rds/src/config.rs | 70 +- sdk/rds/src/config/endpoint.rs | 144 ++-- sdk/rdsdata/src/config.rs | 70 +- sdk/rdsdata/src/config/endpoint.rs | 115 +-- sdk/redshift/src/config.rs | 70 +- sdk/redshift/src/config/endpoint.rs | 144 ++-- sdk/redshiftdata/src/config.rs | 70 +- sdk/redshiftdata/src/config/endpoint.rs | 115 +-- sdk/redshiftserverless/src/config.rs | 70 +- sdk/redshiftserverless/src/config/endpoint.rs | 125 +-- sdk/rekognition/src/config.rs | 70 +- sdk/rekognition/src/config/endpoint.rs | 133 ++-- sdk/resiliencehub/src/config.rs | 70 +- sdk/resiliencehub/src/config/endpoint.rs | 134 ++-- sdk/resourceexplorer2/src/config.rs | 70 +- sdk/resourceexplorer2/src/config/endpoint.rs | 100 ++- sdk/resourcegroups/src/config.rs | 70 +- sdk/resourcegroups/src/config/endpoint.rs | 142 ++-- sdk/resourcegroupstagging/src/config.rs | 70 +- .../src/config/endpoint.rs | 138 ++-- sdk/robomaker/src/config.rs | 70 +- sdk/robomaker/src/config/endpoint.rs | 122 +-- sdk/rolesanywhere/src/config.rs | 70 +- sdk/rolesanywhere/src/config/endpoint.rs | 133 ++-- sdk/route53/src/config.rs | 70 +- sdk/route53/src/config/endpoint.rs | 122 +-- sdk/route53/src/operation/get_change.rs | 4 +- .../operation/get_reusable_delegation_set.rs | 4 +- .../operation/list_resource_record_sets.rs | 4 +- sdk/route53domains/src/config.rs | 70 +- sdk/route53domains/src/config/endpoint.rs | 115 +-- sdk/route53recoverycluster/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- .../src/config.rs | 70 +- .../src/config/endpoint.rs | 116 +-- sdk/route53recoveryreadiness/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/route53resolver/src/config.rs | 70 +- sdk/route53resolver/src/config/endpoint.rs | 139 ++-- sdk/rum/src/config.rs | 70 +- sdk/rum/src/config/endpoint.rs | 124 +-- sdk/s3/src/config.rs | 70 +- sdk/s3/src/config/endpoint.rs | 362 ++------- .../src/operation/create_multipart_upload.rs | 4 +- sdk/s3/src/operation/head_object.rs | 4 +- .../put_bucket_lifecycle_configuration.rs | 4 +- sdk/s3/src/operation/put_object.rs | 8 +- sdk/s3control/src/config.rs | 70 +- sdk/s3control/src/config/endpoint.rs | 203 ++--- sdk/s3outposts/src/config.rs | 70 +- sdk/s3outposts/src/config/endpoint.rs | 135 ++-- sdk/sagemaker/src/config.rs | 70 +- sdk/sagemaker/src/config/endpoint.rs | 141 ++-- sdk/sagemakera2iruntime/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/sagemakeredge/src/config.rs | 70 +- sdk/sagemakeredge/src/config/endpoint.rs | 120 +-- .../src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/sagemakergeospatial/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/sagemakermetrics/src/config.rs | 70 +- sdk/sagemakermetrics/src/config/endpoint.rs | 115 +-- sdk/sagemakerruntime/src/config.rs | 70 +- sdk/sagemakerruntime/src/config/endpoint.rs | 141 ++-- sdk/savingsplans/src/config.rs | 70 +- sdk/savingsplans/src/config/endpoint.rs | 116 +-- sdk/scheduler/src/config.rs | 70 +- sdk/scheduler/src/config/endpoint.rs | 115 +-- sdk/schemas/src/config.rs | 70 +- sdk/schemas/src/config/endpoint.rs | 131 ++-- sdk/secretsmanager/src/config.rs | 70 +- sdk/secretsmanager/src/config/endpoint.rs | 143 ++-- sdk/securityhub/src/config.rs | 70 +- sdk/securityhub/src/config/endpoint.rs | 142 ++-- sdk/securitylake/src/config.rs | 70 +- sdk/securitylake/src/config/endpoint.rs | 115 +-- .../src/config.rs | 70 +- .../src/config/endpoint.rs | 135 ++-- sdk/servicecatalog/src/config.rs | 70 +- sdk/servicecatalog/src/config/endpoint.rs | 142 ++-- sdk/servicecatalogappregistry/src/config.rs | 70 +- .../src/config/endpoint.rs | 141 ++-- sdk/servicediscovery/src/config.rs | 70 +- sdk/servicediscovery/src/config/endpoint.rs | 141 ++-- sdk/servicequotas/src/config.rs | 70 +- sdk/servicequotas/src/config/endpoint.rs | 138 ++-- sdk/ses/src/config.rs | 70 +- sdk/ses/src/config/endpoint.rs | 137 ++-- sdk/sesv2/src/config.rs | 70 +- sdk/sesv2/src/config/endpoint.rs | 137 ++-- sdk/sfn/src/config.rs | 70 +- sdk/sfn/src/config/endpoint.rs | 143 ++-- sdk/shield/src/config.rs | 70 +- sdk/shield/src/config/endpoint.rs | 117 +-- sdk/signer/src/config.rs | 70 +- sdk/signer/src/config/endpoint.rs | 115 +-- sdk/simspaceweaver/src/config.rs | 70 +- sdk/simspaceweaver/src/config/endpoint.rs | 115 +-- sdk/sms/src/config.rs | 70 +- sdk/sms/src/config/endpoint.rs | 140 ++-- sdk/snowball/src/config.rs | 70 +- sdk/snowball/src/config/endpoint.rs | 153 ++-- sdk/snowdevicemanagement/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/sns/src/config.rs | 70 +- sdk/sns/src/config/endpoint.rs | 143 ++-- sdk/sqs/src/config.rs | 70 +- sdk/sqs/src/config/endpoint.rs | 142 ++-- .../operation/change_message_visibility.rs | 4 +- sdk/ssm/src/config.rs | 70 +- sdk/ssm/src/config/endpoint.rs | 143 ++-- sdk/ssmcontacts/src/config.rs | 70 +- sdk/ssmcontacts/src/config/endpoint.rs | 115 +-- sdk/ssmincidents/src/config.rs | 70 +- sdk/ssmincidents/src/config/endpoint.rs | 130 ++-- sdk/ssmsap/src/config.rs | 70 +- sdk/ssmsap/src/config/endpoint.rs | 115 +-- sdk/sso/src/config.rs | 70 +- sdk/sso/src/config/endpoint.rs | 134 ++-- sdk/ssoadmin/src/config.rs | 70 +- sdk/ssoadmin/src/config/endpoint.rs | 135 ++-- sdk/ssooidc/src/config.rs | 70 +- sdk/ssooidc/src/config/endpoint.rs | 134 ++-- sdk/storagegateway/src/config.rs | 70 +- sdk/storagegateway/src/config/endpoint.rs | 143 ++-- sdk/sts/src/config.rs | 70 +- sdk/sts/src/config/endpoint.rs | 163 ++-- sdk/support/src/config.rs | 70 +- sdk/support/src/config/endpoint.rs | 120 +-- sdk/supportapp/src/config.rs | 70 +- sdk/supportapp/src/config/endpoint.rs | 115 +-- sdk/swf/src/config.rs | 70 +- sdk/swf/src/config/endpoint.rs | 143 ++-- sdk/synthetics/src/config.rs | 70 +- sdk/synthetics/src/config/endpoint.rs | 142 ++-- sdk/textract/src/config.rs | 70 +- sdk/textract/src/config/endpoint.rs | 133 ++-- sdk/timestreamquery/src/client.rs | 22 +- sdk/timestreamquery/src/config.rs | 70 +- sdk/timestreamquery/src/config/endpoint.rs | 115 +-- sdk/timestreamquery/src/endpoint_discovery.rs | 45 +- sdk/timestreamwrite/src/client.rs | 22 +- sdk/timestreamwrite/src/config.rs | 70 +- sdk/timestreamwrite/src/config/endpoint.rs | 117 +-- sdk/timestreamwrite/src/endpoint_discovery.rs | 45 +- sdk/tnb/src/config.rs | 70 +- sdk/tnb/src/config/endpoint.rs | 115 +-- sdk/transcribe/src/config.rs | 70 +- sdk/transcribe/src/config/endpoint.rs | 140 ++-- sdk/transcribestreaming/Cargo.toml | 4 - sdk/transcribestreaming/src/config.rs | 70 +- .../src/config/endpoint.rs | 127 ++-- sdk/transfer/src/config.rs | 70 +- sdk/transfer/src/config/endpoint.rs | 142 ++-- sdk/translate/src/config.rs | 70 +- sdk/translate/src/config/endpoint.rs | 134 ++-- sdk/verifiedpermissions/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/voiceid/src/config.rs | 70 +- sdk/voiceid/src/config/endpoint.rs | 121 +-- sdk/vpclattice/src/config.rs | 70 +- sdk/vpclattice/src/config/endpoint.rs | 115 +-- sdk/waf/src/config.rs | 70 +- sdk/waf/src/config/endpoint.rs | 117 +-- sdk/wafregional/src/config.rs | 70 +- sdk/wafregional/src/config/endpoint.rs | 161 ++-- sdk/wafv2/src/config.rs | 70 +- sdk/wafv2/src/config/endpoint.rs | 161 ++-- sdk/wellarchitected/src/config.rs | 70 +- sdk/wellarchitected/src/config/endpoint.rs | 132 ++-- sdk/wisdom/src/config.rs | 70 +- sdk/wisdom/src/config/endpoint.rs | 120 +-- sdk/workdocs/src/config.rs | 70 +- sdk/workdocs/src/config/endpoint.rs | 121 +-- sdk/worklink/src/config.rs | 70 +- sdk/worklink/src/config/endpoint.rs | 115 +-- sdk/workmail/src/config.rs | 70 +- sdk/workmail/src/config/endpoint.rs | 117 +-- sdk/workmailmessageflow/src/config.rs | 70 +- .../src/config/endpoint.rs | 115 +-- sdk/workspaces/src/config.rs | 70 +- sdk/workspaces/src/config/endpoint.rs | 130 ++-- sdk/workspacesweb/src/config.rs | 70 +- sdk/workspacesweb/src/config/endpoint.rs | 117 +-- sdk/xray/src/config.rs | 70 +- sdk/xray/src/config/endpoint.rs | 142 ++-- versions.toml | 718 +++++++++--------- 731 files changed, 33549 insertions(+), 38491 deletions(-) diff --git a/sdk/accessanalyzer/src/config.rs b/sdk/accessanalyzer/src/config.rs index 9b0490c0d371..a0941ecdf8c4 100644 --- a/sdk/accessanalyzer/src/config.rs +++ b/sdk/accessanalyzer/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_accessanalyzer`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_accessanalyzer::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_accessanalyzer::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_accessanalyzer::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_accessanalyzer::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_accessanalyzer::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_accessanalyzer`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/accessanalyzer/src/config/endpoint.rs b/sdk/accessanalyzer/src/config/endpoint.rs index 35c667f85161..20b93558ee66 100644 --- a/sdk/accessanalyzer/src/config/endpoint.rs +++ b/sdk/accessanalyzer/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Access Analyzer +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/account/src/config.rs b/sdk/account/src/config.rs index 35118f4d5dbd..ba600b87047d 100644 --- a/sdk/account/src/config.rs +++ b/sdk/account/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_account`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_account::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_account::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_account::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_account::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_account::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_account`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/account/src/config/endpoint.rs b/sdk/account/src/config/endpoint.rs index 39cb74418f4e..505528810e26 100644 --- a/sdk/account/src/config/endpoint.rs +++ b/sdk/account/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -165,7 +160,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -186,7 +180,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -207,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -228,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -259,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -280,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -301,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -322,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -343,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -362,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -383,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -399,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -420,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -439,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -460,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -476,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -497,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -517,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -536,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -553,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -573,7 +548,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -582,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Account +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -618,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/acm/src/config.rs b/sdk/acm/src/config.rs index 34c32846f713..bec34a6f273e 100644 --- a/sdk/acm/src/config.rs +++ b/sdk/acm/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_acm`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_acm::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_acm::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_acm::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_acm::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_acm::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_acm`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/acm/src/config/endpoint.rs b/sdk/acm/src/config/endpoint.rs index 0efa765771e6..df418afc493b 100644 --- a/sdk/acm/src/config/endpoint.rs +++ b/sdk/acm/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Certificate Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/acmpca/src/config.rs b/sdk/acmpca/src/config.rs index 917287fbadc4..7ac92535ee52 100644 --- a/sdk/acmpca/src/config.rs +++ b/sdk/acmpca/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_acmpca`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_acmpca::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_acmpca::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_acmpca::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_acmpca::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_acmpca::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_acmpca`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/acmpca/src/config/endpoint.rs b/sdk/acmpca/src/config/endpoint.rs index 0878921ce784..b931f3250099 100644 --- a/sdk/acmpca/src/config/endpoint.rs +++ b/sdk/acmpca/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Certificate Manager Private Certificate Authority +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/alexaforbusiness/src/config.rs b/sdk/alexaforbusiness/src/config.rs index 1261a11db744..429728b06c92 100644 --- a/sdk/alexaforbusiness/src/config.rs +++ b/sdk/alexaforbusiness/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_alexaforbusiness`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_alexaforbusiness::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_alexaforbusiness::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_alexaforbusiness::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_alexaforbusiness::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_alexaforbusiness::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_alexaforbusiness`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/alexaforbusiness/src/config/endpoint.rs b/sdk/alexaforbusiness/src/config/endpoint.rs index 44d2435225bf..5ec4130991d0 100644 --- a/sdk/alexaforbusiness/src/config/endpoint.rs +++ b/sdk/alexaforbusiness/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Alexa For Business +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/amp/src/config.rs b/sdk/amp/src/config.rs index 8d401e995683..f399df0ef706 100644 --- a/sdk/amp/src/config.rs +++ b/sdk/amp/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amp`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_amp::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_amp::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_amp::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_amp::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_amp::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amp`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/amp/src/config/endpoint.rs b/sdk/amp/src/config/endpoint.rs index a81b3dfae56d..d359be742109 100644 --- a/sdk/amp/src/config/endpoint.rs +++ b/sdk/amp/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -624,7 +595,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -643,7 +613,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -660,7 +629,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -680,7 +648,6 @@ mod test { /// Missing region #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -689,6 +656,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Prometheus Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -725,27 +756,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/amplify/src/config.rs b/sdk/amplify/src/config.rs index e8232aa2d8f3..5e6ad4701cfe 100644 --- a/sdk/amplify/src/config.rs +++ b/sdk/amplify/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amplify`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_amplify::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_amplify::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_amplify::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_amplify::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_amplify::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amplify`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/amplify/src/config/endpoint.rs b/sdk/amplify/src/config/endpoint.rs index cbc9505ee0d6..763b0c9cbe4d 100644 --- a/sdk/amplify/src/config/endpoint.rs +++ b/sdk/amplify/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -658,7 +628,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -695,7 +663,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -735,7 +701,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -772,7 +736,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -813,7 +775,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -832,7 +793,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -849,7 +809,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -869,7 +828,6 @@ mod test { /// Missing region #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -878,6 +836,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Amplify +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -914,27 +936,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/amplifybackend/src/config.rs b/sdk/amplifybackend/src/config.rs index fff987a6cd9b..10514b44a4f2 100644 --- a/sdk/amplifybackend/src/config.rs +++ b/sdk/amplifybackend/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amplifybackend`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_amplifybackend::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_amplifybackend::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_amplifybackend::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_amplifybackend::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_amplifybackend::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amplifybackend`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/amplifybackend/src/config/endpoint.rs b/sdk/amplifybackend/src/config/endpoint.rs index e0328fd62cd9..3ae8fce4e519 100644 --- a/sdk/amplifybackend/src/config/endpoint.rs +++ b/sdk/amplifybackend/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -751,7 +716,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -771,7 +735,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -790,7 +753,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +769,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -827,7 +788,6 @@ mod test { /// Missing region #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -836,6 +796,70 @@ mod test { } } +/// Endpoint resolver trait specific to AmplifyBackend +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -872,27 +896,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/amplifyuibuilder/src/config.rs b/sdk/amplifyuibuilder/src/config.rs index 54449c7339e9..114a0650e121 100644 --- a/sdk/amplifyuibuilder/src/config.rs +++ b/sdk/amplifyuibuilder/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amplifyuibuilder`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_amplifyuibuilder::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_amplifyuibuilder::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_amplifyuibuilder::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_amplifyuibuilder::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_amplifyuibuilder::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_amplifyuibuilder`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/amplifyuibuilder/src/config/endpoint.rs b/sdk/amplifyuibuilder/src/config/endpoint.rs index 89e888f9ade0..dbfc39e1152a 100644 --- a/sdk/amplifyuibuilder/src/config/endpoint.rs +++ b/sdk/amplifyuibuilder/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -751,7 +716,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -771,7 +735,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -790,7 +753,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +769,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -827,7 +788,6 @@ mod test { /// Missing region #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -836,6 +796,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Amplify UI Builder +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -872,27 +896,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/apigateway/src/config.rs b/sdk/apigateway/src/config.rs index 4a560a9cfa4f..7cf684f503e5 100644 --- a/sdk/apigateway/src/config.rs +++ b/sdk/apigateway/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apigateway`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_apigateway::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_apigateway::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_apigateway::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_apigateway::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_apigateway::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apigateway`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1143,7 +1125,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/apigateway/src/config/endpoint.rs b/sdk/apigateway/src/config/endpoint.rs index 3ae274bd9560..e9a10d3594a7 100644 --- a/sdk/apigateway/src/config/endpoint.rs +++ b/sdk/apigateway/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon API Gateway +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/apigatewaymanagement/src/config.rs b/sdk/apigatewaymanagement/src/config.rs index 3e22974e6360..4410cd5a3579 100644 --- a/sdk/apigatewaymanagement/src/config.rs +++ b/sdk/apigatewaymanagement/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apigatewaymanagement`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_apigatewaymanagement::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_apigatewaymanagement::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_apigatewaymanagement::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_apigatewaymanagement::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_apigatewaymanagement::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apigatewaymanagement`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/apigatewaymanagement/src/config/endpoint.rs b/sdk/apigatewaymanagement/src/config/endpoint.rs index bcc3f419f877..9581fcb65a2e 100644 --- a/sdk/apigatewaymanagement/src/config/endpoint.rs +++ b/sdk/apigatewaymanagement/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AmazonApiGatewayManagementApi +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/apigatewayv2/src/config.rs b/sdk/apigatewayv2/src/config.rs index 4b4ab964b801..8f830826dc74 100644 --- a/sdk/apigatewayv2/src/config.rs +++ b/sdk/apigatewayv2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apigatewayv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_apigatewayv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_apigatewayv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_apigatewayv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_apigatewayv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_apigatewayv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apigatewayv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/apigatewayv2/src/config/endpoint.rs b/sdk/apigatewayv2/src/config/endpoint.rs index 3ae274bd9560..6de0eb1c37ca 100644 --- a/sdk/apigatewayv2/src/config/endpoint.rs +++ b/sdk/apigatewayv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to AmazonApiGatewayV2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appconfig/src/config.rs b/sdk/appconfig/src/config.rs index e19b7c1314d9..1f7f4ba732a0 100644 --- a/sdk/appconfig/src/config.rs +++ b/sdk/appconfig/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appconfig`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appconfig::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appconfig::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appconfig::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appconfig::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appconfig::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appconfig`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appconfig/src/config/endpoint.rs b/sdk/appconfig/src/config/endpoint.rs index b0093d249f44..feb3e62d2094 100644 --- a/sdk/appconfig/src/config/endpoint.rs +++ b/sdk/appconfig/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -960,7 +915,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -979,7 +933,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -996,7 +949,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1016,7 +968,6 @@ mod test { /// Missing region #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1025,6 +976,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon AppConfig +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1061,27 +1076,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appconfigdata/src/config.rs b/sdk/appconfigdata/src/config.rs index 7d0445c965c2..327a0485d251 100644 --- a/sdk/appconfigdata/src/config.rs +++ b/sdk/appconfigdata/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appconfigdata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appconfigdata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appconfigdata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appconfigdata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appconfigdata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appconfigdata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appconfigdata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appconfigdata/src/config/endpoint.rs b/sdk/appconfigdata/src/config/endpoint.rs index a178653182b0..f34553d24a78 100644 --- a/sdk/appconfigdata/src/config/endpoint.rs +++ b/sdk/appconfigdata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -918,7 +875,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -937,7 +893,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +909,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -974,7 +928,6 @@ mod test { /// Missing region #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -983,6 +936,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS AppConfig Data +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1019,27 +1036,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appfabric/src/config.rs b/sdk/appfabric/src/config.rs index 152ee795fc08..9d9fcd3f9143 100644 --- a/sdk/appfabric/src/config.rs +++ b/sdk/appfabric/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appfabric`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appfabric::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appfabric::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appfabric::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appfabric::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appfabric::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appfabric`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appfabric/src/config/endpoint.rs b/sdk/appfabric/src/config/endpoint.rs index b85554ada793..a231080fbf6c 100644 --- a/sdk/appfabric/src/config/endpoint.rs +++ b/sdk/appfabric/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AppFabric +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appflow/src/config.rs b/sdk/appflow/src/config.rs index 2dabc616b908..bdb135300c88 100644 --- a/sdk/appflow/src/config.rs +++ b/sdk/appflow/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appflow`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appflow::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appflow::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appflow::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appflow::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appflow::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appflow`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appflow/src/config/endpoint.rs b/sdk/appflow/src/config/endpoint.rs index 674f2f46fa05..87842e2d82f4 100644 --- a/sdk/appflow/src/config/endpoint.rs +++ b/sdk/appflow/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Appflow +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appintegrations/src/config.rs b/sdk/appintegrations/src/config.rs index 5de52093d65a..2d5917c40a44 100644 --- a/sdk/appintegrations/src/config.rs +++ b/sdk/appintegrations/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appintegrations`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appintegrations::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appintegrations::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appintegrations::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appintegrations::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appintegrations::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appintegrations`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appintegrations/src/config/endpoint.rs b/sdk/appintegrations/src/config/endpoint.rs index d89ff3ddcc32..9dab4294129c 100644 --- a/sdk/appintegrations/src/config/endpoint.rs +++ b/sdk/appintegrations/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -624,7 +595,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -643,7 +613,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -660,7 +629,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -680,7 +648,6 @@ mod test { /// Missing region #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -689,6 +656,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon AppIntegrations Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -725,27 +756,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/applicationautoscaling/src/config.rs b/sdk/applicationautoscaling/src/config.rs index 23110332c73a..62c91b206baa 100644 --- a/sdk/applicationautoscaling/src/config.rs +++ b/sdk/applicationautoscaling/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationautoscaling`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_applicationautoscaling::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_applicationautoscaling::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_applicationautoscaling::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_applicationautoscaling::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_applicationautoscaling::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationautoscaling`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/applicationautoscaling/src/config/endpoint.rs b/sdk/applicationautoscaling/src/config/endpoint.rs index ccc1103d838d..f15d3492fe16 100644 --- a/sdk/applicationautoscaling/src/config/endpoint.rs +++ b/sdk/applicationautoscaling/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -960,7 +915,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -979,7 +933,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -996,7 +949,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1016,7 +968,6 @@ mod test { /// Missing region #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1025,6 +976,70 @@ mod test { } } +/// Endpoint resolver trait specific to Application Auto Scaling +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1061,27 +1076,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/applicationcostprofiler/src/config.rs b/sdk/applicationcostprofiler/src/config.rs index bb405f9cb22e..4b1776bdf246 100644 --- a/sdk/applicationcostprofiler/src/config.rs +++ b/sdk/applicationcostprofiler/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationcostprofiler`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_applicationcostprofiler::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_applicationcostprofiler::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_applicationcostprofiler::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_applicationcostprofiler::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_applicationcostprofiler::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationcostprofiler`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/applicationcostprofiler/src/config/endpoint.rs b/sdk/applicationcostprofiler/src/config/endpoint.rs index 96e081e6789b..f19d434ea4be 100644 --- a/sdk/applicationcostprofiler/src/config/endpoint.rs +++ b/sdk/applicationcostprofiler/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Application Cost Profiler +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/applicationdiscovery/src/config.rs b/sdk/applicationdiscovery/src/config.rs index df98b8a52bdf..fe01da227891 100644 --- a/sdk/applicationdiscovery/src/config.rs +++ b/sdk/applicationdiscovery/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationdiscovery`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_applicationdiscovery::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_applicationdiscovery::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_applicationdiscovery::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_applicationdiscovery::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_applicationdiscovery::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationdiscovery`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/applicationdiscovery/src/config/endpoint.rs b/sdk/applicationdiscovery/src/config/endpoint.rs index d2df236c4f0a..5edddcce82c4 100644 --- a/sdk/applicationdiscovery/src/config/endpoint.rs +++ b/sdk/applicationdiscovery/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Application Discovery Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/applicationinsights/src/config.rs b/sdk/applicationinsights/src/config.rs index 2c3d9be32407..a5fb36339c3e 100644 --- a/sdk/applicationinsights/src/config.rs +++ b/sdk/applicationinsights/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationinsights`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_applicationinsights::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_applicationinsights::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_applicationinsights::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_applicationinsights::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_applicationinsights::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_applicationinsights`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/applicationinsights/src/config/endpoint.rs b/sdk/applicationinsights/src/config/endpoint.rs index 2c33ce00391b..8fc390dd5cad 100644 --- a/sdk/applicationinsights/src/config/endpoint.rs +++ b/sdk/applicationinsights/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudWatch Application Insights +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appmesh/src/config.rs b/sdk/appmesh/src/config.rs index 34eff9c0284a..d20f7476d418 100644 --- a/sdk/appmesh/src/config.rs +++ b/sdk/appmesh/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appmesh`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appmesh::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appmesh::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appmesh::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appmesh::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appmesh::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appmesh`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appmesh/src/config/endpoint.rs b/sdk/appmesh/src/config/endpoint.rs index cf51b976420e..19698d672c5c 100644 --- a/sdk/appmesh/src/config/endpoint.rs +++ b/sdk/appmesh/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -870,7 +830,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +850,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -912,7 +870,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -933,7 +890,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -954,7 +910,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -975,7 +930,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -996,7 +950,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1017,7 +970,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1038,7 +990,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1059,7 +1010,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1080,7 +1030,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1101,7 +1050,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1120,7 +1068,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1141,7 +1088,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1157,7 +1103,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1178,7 +1123,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1197,7 +1141,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1218,7 +1161,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1234,7 +1176,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1255,7 +1196,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1275,7 +1215,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1294,7 +1233,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1311,7 +1249,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1331,7 +1268,6 @@ mod test { /// Missing region #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1340,6 +1276,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS App Mesh +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1376,27 +1376,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/apprunner/src/config.rs b/sdk/apprunner/src/config.rs index 7cbbce2d4f16..6f74e7a0f660 100644 --- a/sdk/apprunner/src/config.rs +++ b/sdk/apprunner/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apprunner`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_apprunner::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_apprunner::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_apprunner::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_apprunner::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_apprunner::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_apprunner`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/apprunner/src/config/endpoint.rs b/sdk/apprunner/src/config/endpoint.rs index 5838e800f8bb..799b5dc055bb 100644 --- a/sdk/apprunner/src/config/endpoint.rs +++ b/sdk/apprunner/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS App Runner +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appstream/src/config.rs b/sdk/appstream/src/config.rs index 6ddc8331a650..c58d36bd169b 100644 --- a/sdk/appstream/src/config.rs +++ b/sdk/appstream/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appstream`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appstream::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appstream::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appstream::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appstream::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appstream::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appstream`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appstream/src/config/endpoint.rs b/sdk/appstream/src/config/endpoint.rs index 056d710f8d53..9d97731414b7 100644 --- a/sdk/appstream/src/config/endpoint.rs +++ b/sdk/appstream/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -729,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -748,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -765,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -785,7 +748,6 @@ mod test { /// Missing region #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -794,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon AppStream +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -830,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/appsync/src/config.rs b/sdk/appsync/src/config.rs index 675c7b85be53..c776c2e9b3d8 100644 --- a/sdk/appsync/src/config.rs +++ b/sdk/appsync/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appsync`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_appsync::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_appsync::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_appsync::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_appsync::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_appsync::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_appsync`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/appsync/src/config/endpoint.rs b/sdk/appsync/src/config/endpoint.rs index 98a132329a28..02e7e04e7cda 100644 --- a/sdk/appsync/src/config/endpoint.rs +++ b/sdk/appsync/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS AppSync +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/arczonalshift/src/config.rs b/sdk/arczonalshift/src/config.rs index e79f0f4ee587..8d518bc3ca91 100644 --- a/sdk/arczonalshift/src/config.rs +++ b/sdk/arczonalshift/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_arczonalshift`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_arczonalshift::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_arczonalshift::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_arczonalshift::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_arczonalshift::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_arczonalshift::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_arczonalshift`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/arczonalshift/src/config/endpoint.rs b/sdk/arczonalshift/src/config/endpoint.rs index f2f895d2bef7..10d783ea54af 100644 --- a/sdk/arczonalshift/src/config/endpoint.rs +++ b/sdk/arczonalshift/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS ARC - Zonal Shift +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/athena/src/config.rs b/sdk/athena/src/config.rs index 780e7ba25e75..1f4b7073386d 100644 --- a/sdk/athena/src/config.rs +++ b/sdk/athena/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_athena`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_athena::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_athena::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_athena::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_athena::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_athena::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_athena`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/athena/src/config/endpoint.rs b/sdk/athena/src/config/endpoint.rs index 11e56fa6dc7c..64141fddc88d 100644 --- a/sdk/athena/src/config/endpoint.rs +++ b/sdk/athena/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Athena +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/auditmanager/src/config.rs b/sdk/auditmanager/src/config.rs index c343460f9811..c1e4def8051f 100644 --- a/sdk/auditmanager/src/config.rs +++ b/sdk/auditmanager/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_auditmanager`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_auditmanager::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_auditmanager::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_auditmanager::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_auditmanager::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_auditmanager::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_auditmanager`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/auditmanager/src/config/endpoint.rs b/sdk/auditmanager/src/config/endpoint.rs index a4cf536f391f..1b08f55885c9 100644 --- a/sdk/auditmanager/src/config/endpoint.rs +++ b/sdk/auditmanager/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -666,7 +635,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -685,7 +653,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -702,7 +669,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -722,7 +688,6 @@ mod test { /// Missing region #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -731,6 +696,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Audit Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -767,27 +796,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/autoscaling/src/config.rs b/sdk/autoscaling/src/config.rs index 08b76baef10f..beb104d3d24e 100644 --- a/sdk/autoscaling/src/config.rs +++ b/sdk/autoscaling/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_autoscaling`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_autoscaling::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_autoscaling::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_autoscaling::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_autoscaling::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_autoscaling::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_autoscaling`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/autoscaling/src/config/endpoint.rs b/sdk/autoscaling/src/config/endpoint.rs index 6a8ba2931bdb..1dd162f6720b 100644 --- a/sdk/autoscaling/src/config/endpoint.rs +++ b/sdk/autoscaling/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to Auto Scaling +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/autoscalingplans/src/config.rs b/sdk/autoscalingplans/src/config.rs index 489254086752..6094420a910d 100644 --- a/sdk/autoscalingplans/src/config.rs +++ b/sdk/autoscalingplans/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_autoscalingplans`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_autoscalingplans::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_autoscalingplans::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_autoscalingplans::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_autoscalingplans::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_autoscalingplans::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_autoscalingplans`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/autoscalingplans/src/config/endpoint.rs b/sdk/autoscalingplans/src/config/endpoint.rs index 3289066fb21d..a72542b6011a 100644 --- a/sdk/autoscalingplans/src/config/endpoint.rs +++ b/sdk/autoscalingplans/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -918,7 +875,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -937,7 +893,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +909,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -974,7 +928,6 @@ mod test { /// Missing region #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -983,6 +936,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Auto Scaling Plans +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1019,27 +1036,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/aws-smithy-http/src/endpoint.rs b/sdk/aws-smithy-http/src/endpoint.rs index 78ea5b2a3491..ce7c79900f3b 100644 --- a/sdk/aws-smithy-http/src/endpoint.rs +++ b/sdk/aws-smithy-http/src/endpoint.rs @@ -5,94 +5,22 @@ //! Code for resolving an endpoint (URI) that a request should be sent to -use crate::endpoint::error::InvalidEndpointError; -use aws_smithy_types::config_bag::{Storable, StoreReplace}; -use http::uri::{Authority, Uri}; use std::borrow::Cow; -use std::fmt::{Debug, Formatter}; +use std::fmt::Debug; use std::result::Result as StdResult; use std::str::FromStr; -use std::sync::Arc; -pub mod error; +use http::uri::{Authority, Uri}; +use aws_smithy_types::config_bag::{Storable, StoreReplace}; pub use error::ResolveEndpointError; -/// An endpoint-resolution-specific Result. Contains either an [`Endpoint`](aws_smithy_types::endpoint::Endpoint) or a [`ResolveEndpointError`]. -pub type Result = std::result::Result; - -/// Implementors of this trait can resolve an endpoint that will be applied to a request. -pub trait ResolveEndpoint: Send + Sync { - /// Given some endpoint parameters, resolve an endpoint or return an error when resolution is - /// impossible. - fn resolve_endpoint(&self, params: &Params) -> Result; -} - -impl ResolveEndpoint for &'static str { - fn resolve_endpoint(&self, _params: &T) -> Result { - Ok(aws_smithy_types::endpoint::Endpoint::builder() - .url(*self) - .build()) - } -} - -/// Endpoint Resolver wrapper that may be shared -#[derive(Clone)] -pub struct SharedEndpointResolver(Arc>); - -impl Debug for SharedEndpointResolver { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.debug_struct("SharedEndpointResolver").finish() - } -} - -impl SharedEndpointResolver { - /// Create a new `SharedEndpointResolver` from `ResolveEndpoint` - pub fn new(resolve_endpoint: impl ResolveEndpoint + 'static) -> Self { - Self(Arc::new(resolve_endpoint)) - } -} - -impl AsRef> for SharedEndpointResolver { - fn as_ref(&self) -> &(dyn ResolveEndpoint + 'static) { - self.0.as_ref() - } -} - -impl From>> for SharedEndpointResolver { - fn from(resolve_endpoint: Arc>) -> Self { - SharedEndpointResolver(resolve_endpoint) - } -} - -impl ResolveEndpoint for SharedEndpointResolver { - fn resolve_endpoint(&self, params: &T) -> Result { - self.0.resolve_endpoint(params) - } -} - -/// API Endpoint -/// -/// This implements an API endpoint as specified in the -/// [Smithy Endpoint Specification](https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html) -#[derive(Clone, Debug)] -#[deprecated(note = "Use `.endpoint_url(...)` directly instead")] -pub struct Endpoint { - uri: http::Uri, +use crate::endpoint::error::InvalidEndpointError; - /// If true, endpointPrefix does ignored when setting the endpoint on a request - immutable: bool, -} +pub mod error; -#[allow(deprecated)] -/// This allows customers that use `Endpoint` to override the endpoint to continue to do so -impl ResolveEndpoint for Endpoint { - fn resolve_endpoint(&self, _params: &T) -> Result { - Ok(aws_smithy_types::endpoint::Endpoint::builder() - .url(self.uri.to_string()) - .build()) - } -} +/// An endpoint-resolution-specific Result. Contains either an [`Endpoint`](aws_smithy_types::endpoint::Endpoint) or a [`ResolveEndpointError`]. +pub type Result = std::result::Result; /// A special type that adds support for services that have special URL-prefixing rules. #[derive(Clone, Debug, Eq, PartialEq)] @@ -156,95 +84,6 @@ pub fn apply_endpoint( Ok(()) } -#[allow(deprecated)] -impl Endpoint { - /// Create a new endpoint from a URI - /// - /// Certain services will augment the endpoint with additional metadata. For example, - /// S3 can prefix the host with the bucket name. If your endpoint does not support this, - /// (for example, when communicating with localhost), use [`Endpoint::immutable`]. - pub fn mutable_uri(uri: Uri) -> StdResult { - Ok(Endpoint { - uri: Self::validate_endpoint(uri)?, - immutable: false, - }) - } - - /// Create a new endpoint from a URI string - /// - /// Certain services will augment the endpoint with additional metadata. For example, - /// S3 can prefix the host with the bucket name. If your endpoint does not support this, - /// (for example, when communicating with localhost), use [`Endpoint::immutable`]. - pub fn mutable(uri: impl AsRef) -> StdResult { - Self::mutable_uri( - Uri::try_from(uri.as_ref()).map_err(InvalidEndpointError::failed_to_construct_uri)?, - ) - } - - /// Returns the URI of this endpoint - pub fn uri(&self) -> &Uri { - &self.uri - } - - /// Create a new immutable endpoint from a URI - /// - /// ```rust - /// # use aws_smithy_http::endpoint::Endpoint; - /// use http::Uri; - /// let uri = Uri::from_static("http://localhost:8000"); - /// let endpoint = Endpoint::immutable_uri(uri); - /// ``` - /// - /// Certain services will augment the endpoint with additional metadata. For example, - /// S3 can prefix the host with the bucket name. This constructor creates an endpoint which will - /// ignore those mutations. If you want an endpoint which will obey mutation requests, use - /// [`Endpoint::mutable`] instead. - pub fn immutable_uri(uri: Uri) -> StdResult { - Ok(Endpoint { - uri: Self::validate_endpoint(uri)?, - immutable: true, - }) - } - - /// Create a new immutable endpoint from a URI string - /// - /// ```rust - /// # use aws_smithy_http::endpoint::Endpoint; - /// let endpoint = Endpoint::immutable("http://localhost:8000"); - /// ``` - /// - /// Certain services will augment the endpoint with additional metadata. For example, - /// S3 can prefix the host with the bucket name. This constructor creates an endpoint which will - /// ignore those mutations. If you want an endpoint which will obey mutation requests, use - /// [`Endpoint::mutable`] instead. - pub fn immutable(uri: impl AsRef) -> StdResult { - Self::immutable_uri( - Uri::try_from(uri.as_ref()).map_err(InvalidEndpointError::failed_to_construct_uri)?, - ) - } - - /// Sets the endpoint on `uri`, potentially applying the specified `prefix` in the process. - pub fn set_endpoint( - &self, - uri: &mut http::Uri, - prefix: Option<&EndpointPrefix>, - ) -> StdResult<(), InvalidEndpointError> { - let prefix = match self.immutable { - true => None, - false => prefix, - }; - apply_endpoint(uri, &self.uri, prefix) - } - - fn validate_endpoint(endpoint: Uri) -> StdResult { - if endpoint.scheme().is_none() { - Err(InvalidEndpointError::endpoint_must_have_scheme()) - } else { - Ok(endpoint) - } - } -} - fn merge_paths<'a>(endpoint: &'a Uri, uri: &'a Uri) -> Cow<'a, str> { if let Some(query) = endpoint.path_and_query().and_then(|pq| pq.query()) { tracing::warn!(query = %query, "query specified in endpoint will be ignored during endpoint resolution"); @@ -261,103 +100,3 @@ fn merge_paths<'a>(endpoint: &'a Uri, uri: &'a Uri) -> Cow<'a, str> { Cow::Owned(format!("{}/{}", ep_no_slash, uri_path_no_slash)) } } - -#[cfg(test)] -#[allow(deprecated)] -mod test { - use crate::endpoint::error::{InvalidEndpointError, InvalidEndpointErrorKind}; - use crate::endpoint::{Endpoint, EndpointPrefix}; - use http::Uri; - - #[test] - fn prefix_endpoint() { - let ep = Endpoint::mutable("https://us-east-1.dynamo.amazonaws.com").unwrap(); - let mut uri = Uri::from_static("/list_tables?k=v"); - ep.set_endpoint( - &mut uri, - Some(&EndpointPrefix::new("subregion.").expect("valid prefix")), - ) - .unwrap(); - assert_eq!( - uri, - Uri::from_static("https://subregion.us-east-1.dynamo.amazonaws.com/list_tables?k=v") - ); - } - - #[test] - fn prefix_endpoint_custom_port() { - let ep = Endpoint::mutable("https://us-east-1.dynamo.amazonaws.com:6443").unwrap(); - let mut uri = Uri::from_static("/list_tables?k=v"); - ep.set_endpoint( - &mut uri, - Some(&EndpointPrefix::new("subregion.").expect("valid prefix")), - ) - .unwrap(); - assert_eq!( - uri, - Uri::from_static( - "https://subregion.us-east-1.dynamo.amazonaws.com:6443/list_tables?k=v" - ) - ); - } - - #[test] - fn prefix_immutable_endpoint() { - let ep = Endpoint::immutable("https://us-east-1.dynamo.amazonaws.com").unwrap(); - let mut uri = Uri::from_static("/list_tables?k=v"); - ep.set_endpoint( - &mut uri, - Some(&EndpointPrefix::new("subregion.").expect("valid prefix")), - ) - .unwrap(); - assert_eq!( - uri, - Uri::from_static("https://us-east-1.dynamo.amazonaws.com/list_tables?k=v") - ); - } - - #[test] - fn endpoint_with_path() { - for uri in &[ - // check that trailing slashes are properly normalized - "https://us-east-1.dynamo.amazonaws.com/private", - "https://us-east-1.dynamo.amazonaws.com/private/", - ] { - let ep = Endpoint::immutable(uri).unwrap(); - let mut uri = Uri::from_static("/list_tables?k=v"); - ep.set_endpoint( - &mut uri, - Some(&EndpointPrefix::new("subregion.").expect("valid prefix")), - ) - .unwrap(); - assert_eq!( - uri, - Uri::from_static("https://us-east-1.dynamo.amazonaws.com/private/list_tables?k=v") - ); - } - } - - #[test] - fn set_endpoint_empty_path() { - let ep = Endpoint::immutable("http://localhost:8000").unwrap(); - let mut uri = Uri::from_static("/"); - ep.set_endpoint(&mut uri, None).unwrap(); - assert_eq!(uri, Uri::from_static("http://localhost:8000/")) - } - - #[test] - fn endpoint_construction_missing_scheme() { - assert!(matches!( - Endpoint::mutable("localhost:8000"), - Err(InvalidEndpointError { - kind: InvalidEndpointErrorKind::EndpointMustHaveScheme - }) - )); - assert!(matches!( - Endpoint::immutable("localhost:8000"), - Err(InvalidEndpointError { - kind: InvalidEndpointErrorKind::EndpointMustHaveScheme - }) - )); - } -} diff --git a/sdk/aws-smithy-runtime/src/client/orchestrator/endpoints.rs b/sdk/aws-smithy-runtime/src/client/orchestrator/endpoints.rs index 30bbe3e9e384..11f7d873dff5 100644 --- a/sdk/aws-smithy-runtime/src/client/orchestrator/endpoints.rs +++ b/sdk/aws-smithy-runtime/src/client/orchestrator/endpoints.rs @@ -5,7 +5,6 @@ use aws_smithy_http::endpoint::error::ResolveEndpointError; use aws_smithy_http::endpoint::EndpointPrefix; -use aws_smithy_http::endpoint::SharedEndpointResolver; use aws_smithy_runtime_api::box_error::BoxError; use aws_smithy_runtime_api::client::endpoint::{ EndpointFuture, EndpointResolverParams, ResolveEndpoint, @@ -13,7 +12,7 @@ use aws_smithy_runtime_api::client::endpoint::{ use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext; use aws_smithy_runtime_api::client::orchestrator::HttpRequest; use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents; -use aws_smithy_types::config_bag::{ConfigBag, Storable, StoreReplace}; +use aws_smithy_types::config_bag::ConfigBag; use aws_smithy_types::endpoint::Endpoint; use http::header::HeaderName; use http::uri::PathAndQuery; @@ -70,50 +69,6 @@ impl From for EndpointResolverParams { } } -/// Default implementation of [`ResolveEndpoint`]. -/// -/// This default endpoint resolver implements the `ResolveEndpoint` trait by -/// converting the type-erased [`EndpointResolverParams`] into the concrete -/// endpoint params for the service. It then delegates endpoint resolution -/// to an underlying resolver that is aware of the concrete type. -#[derive(Clone, Debug)] -pub struct DefaultEndpointResolver { - inner: SharedEndpointResolver, -} - -impl Storable for DefaultEndpointResolver -where - Params: Debug + Send + Sync + 'static, -{ - type Storer = StoreReplace; -} - -impl DefaultEndpointResolver { - /// Creates a new `DefaultEndpointResolver`. - pub fn new(resolve_endpoint: SharedEndpointResolver) -> Self { - Self { - inner: resolve_endpoint, - } - } -} - -impl ResolveEndpoint for DefaultEndpointResolver -where - Params: Debug + Send + Sync + 'static, -{ - fn resolve_endpoint<'a>(&'a self, params: &'a EndpointResolverParams) -> EndpointFuture<'a> { - use aws_smithy_http::endpoint::ResolveEndpoint as _; - let ep = match params.get::() { - Some(params) => self.inner.resolve_endpoint(params).map_err(Box::new), - None => Err(Box::new(ResolveEndpointError::message( - "params of expected type was not present", - ))), - } - .map_err(|e| e as _); - EndpointFuture::ready(ep) - } -} - pub(super) async fn orchestrate_endpoint( ctx: &mut InterceptorContext, runtime_components: &RuntimeComponents, diff --git a/sdk/backup/src/config.rs b/sdk/backup/src/config.rs index 024b9703b097..9e4fe34411dc 100644 --- a/sdk/backup/src/config.rs +++ b/sdk/backup/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_backup`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_backup::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_backup::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_backup::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_backup::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_backup::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_backup`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/backup/src/config/endpoint.rs b/sdk/backup/src/config/endpoint.rs index 441c9d11ae7e..f623f9ceb3b6 100644 --- a/sdk/backup/src/config/endpoint.rs +++ b/sdk/backup/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -918,7 +875,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -937,7 +893,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +909,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -974,7 +928,6 @@ mod test { /// Missing region #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -983,6 +936,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Backup +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1019,27 +1036,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/backupgateway/src/config.rs b/sdk/backupgateway/src/config.rs index 7fcb5be15ebc..3d372cd80cd3 100644 --- a/sdk/backupgateway/src/config.rs +++ b/sdk/backupgateway/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_backupgateway`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_backupgateway::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_backupgateway::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_backupgateway::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_backupgateway::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_backupgateway::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_backupgateway`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/backupgateway/src/config/endpoint.rs b/sdk/backupgateway/src/config/endpoint.rs index 636686aa1790..cb6715b6a129 100644 --- a/sdk/backupgateway/src/config/endpoint.rs +++ b/sdk/backupgateway/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -876,7 +835,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -895,7 +853,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -912,7 +869,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -932,7 +888,6 @@ mod test { /// Missing region #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -941,6 +896,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Backup Gateway +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -977,27 +996,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/backupstorage/src/config.rs b/sdk/backupstorage/src/config.rs index 75d410e1029f..64ea09d14788 100644 --- a/sdk/backupstorage/src/config.rs +++ b/sdk/backupstorage/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_backupstorage`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_backupstorage::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_backupstorage::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_backupstorage::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_backupstorage::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_backupstorage::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_backupstorage`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/backupstorage/src/config/endpoint.rs b/sdk/backupstorage/src/config/endpoint.rs index c07177834ef0..3643431e84ae 100644 --- a/sdk/backupstorage/src/config/endpoint.rs +++ b/sdk/backupstorage/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Backup Storage +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/batch/src/config.rs b/sdk/batch/src/config.rs index b1a5b1dae75e..6b4fcd0883f9 100644 --- a/sdk/batch/src/config.rs +++ b/sdk/batch/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_batch`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_batch::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_batch::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_batch::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_batch::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_batch::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_batch`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/batch/src/config/endpoint.rs b/sdk/batch/src/config/endpoint.rs index 589b80548373..25734a97e9f8 100644 --- a/sdk/batch/src/config/endpoint.rs +++ b/sdk/batch/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Batch +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/bedrock/src/config.rs b/sdk/bedrock/src/config.rs index 551c04f4fa35..e88d78e37f2c 100644 --- a/sdk/bedrock/src/config.rs +++ b/sdk/bedrock/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_bedrock`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_bedrock::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_bedrock::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_bedrock::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_bedrock::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_bedrock::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_bedrock`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/bedrock/src/config/endpoint.rs b/sdk/bedrock/src/config/endpoint.rs index 130645c4e49c..95f41ba0eac1 100644 --- a/sdk/bedrock/src/config/endpoint.rs +++ b/sdk/bedrock/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Bedrock +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/bedrockruntime/Cargo.toml b/sdk/bedrockruntime/Cargo.toml index a8fc06181430..0b0d8f34d515 100644 --- a/sdk/bedrockruntime/Cargo.toml +++ b/sdk/bedrockruntime/Cargo.toml @@ -80,10 +80,6 @@ path = "../aws-credential-types" features = ["test-util"] version = "0.56.1" -[dev-dependencies.aws-smithy-http] -path = "../aws-smithy-http" -version = "0.56.1" - [dev-dependencies.tokio] version = "1.23.1" features = ["macros", "test-util", "rt-multi-thread"] diff --git a/sdk/bedrockruntime/src/config.rs b/sdk/bedrockruntime/src/config.rs index 38fb0f85d43c..3aa8dfafb581 100644 --- a/sdk/bedrockruntime/src/config.rs +++ b/sdk/bedrockruntime/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_bedrockruntime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_bedrockruntime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_bedrockruntime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_bedrockruntime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_bedrockruntime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_bedrockruntime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_bedrockruntime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/bedrockruntime/src/config/endpoint.rs b/sdk/bedrockruntime/src/config/endpoint.rs index 54c67510d8e9..b22f1918a32d 100644 --- a/sdk/bedrockruntime/src/config/endpoint.rs +++ b/sdk/bedrockruntime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Bedrock Runtime +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/billingconductor/src/config.rs b/sdk/billingconductor/src/config.rs index 1c60f2220ae0..36485b12839d 100644 --- a/sdk/billingconductor/src/config.rs +++ b/sdk/billingconductor/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_billingconductor`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_billingconductor::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_billingconductor::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_billingconductor::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_billingconductor::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_billingconductor::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_billingconductor`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/billingconductor/src/config/endpoint.rs b/sdk/billingconductor/src/config/endpoint.rs index 31ba6ed063c9..44816a1eeeb4 100644 --- a/sdk/billingconductor/src/config/endpoint.rs +++ b/sdk/billingconductor/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -155,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -176,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -197,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -218,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -239,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -260,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -281,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -302,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -321,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -342,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -358,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -379,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -398,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -419,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -435,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -456,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -476,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -495,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -512,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -532,7 +508,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -541,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWSBillingConductor +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -577,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/braket/src/config.rs b/sdk/braket/src/config.rs index 5856564a4c51..2775fe4a55af 100644 --- a/sdk/braket/src/config.rs +++ b/sdk/braket/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_braket`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_braket::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_braket::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_braket::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_braket::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_braket::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_braket`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/braket/src/config/endpoint.rs b/sdk/braket/src/config/endpoint.rs index b72399d1428d..5502f7ae6396 100644 --- a/sdk/braket/src/config/endpoint.rs +++ b/sdk/braket/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -498,7 +475,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -517,7 +493,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -534,7 +509,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -554,7 +528,6 @@ mod test { /// Missing region #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -563,6 +536,70 @@ mod test { } } +/// Endpoint resolver trait specific to Braket +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -599,27 +636,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/budgets/src/config.rs b/sdk/budgets/src/config.rs index 720a02b74445..49a2cf7f3d50 100644 --- a/sdk/budgets/src/config.rs +++ b/sdk/budgets/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_budgets`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_budgets::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_budgets::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_budgets::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_budgets::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_budgets::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_budgets`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/budgets/src/config/endpoint.rs b/sdk/budgets/src/config/endpoint.rs index a99e82b9db22..50bb8b355cc9 100644 --- a/sdk/budgets/src/config/endpoint.rs +++ b/sdk/budgets/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -165,7 +160,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -186,7 +180,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -207,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -228,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -259,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -280,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -301,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -322,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -343,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -362,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -383,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -399,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -420,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -439,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -460,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -476,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -497,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -517,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -536,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -553,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -573,7 +548,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -582,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Budgets +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -618,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/chime/src/config.rs b/sdk/chime/src/config.rs index 60ccbf16f648..bcf86a4a195c 100644 --- a/sdk/chime/src/config.rs +++ b/sdk/chime/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_chime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_chime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_chime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_chime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_chime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/chime/src/config/endpoint.rs b/sdk/chime/src/config/endpoint.rs index 71e45432cb1c..4ffec243af07 100644 --- a/sdk/chime/src/config/endpoint.rs +++ b/sdk/chime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -155,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -176,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -197,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -218,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -239,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -260,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -281,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -302,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -321,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -342,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -358,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -379,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -398,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -419,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -435,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -456,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -476,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -495,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -512,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -532,7 +508,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -541,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Chime +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -577,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/chimesdkidentity/src/config.rs b/sdk/chimesdkidentity/src/config.rs index 513e12a5f69a..96279e208a89 100644 --- a/sdk/chimesdkidentity/src/config.rs +++ b/sdk/chimesdkidentity/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkidentity`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_chimesdkidentity::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_chimesdkidentity::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_chimesdkidentity::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_chimesdkidentity::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_chimesdkidentity::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkidentity`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/chimesdkidentity/src/config/endpoint.rs b/sdk/chimesdkidentity/src/config/endpoint.rs index 671f12c38f59..a5755c69d541 100644 --- a/sdk/chimesdkidentity/src/config/endpoint.rs +++ b/sdk/chimesdkidentity/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Chime SDK Identity +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/chimesdkmediapipelines/src/config.rs b/sdk/chimesdkmediapipelines/src/config.rs index f405e761d9cd..138e0fdbd803 100644 --- a/sdk/chimesdkmediapipelines/src/config.rs +++ b/sdk/chimesdkmediapipelines/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkmediapipelines`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_chimesdkmediapipelines::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_chimesdkmediapipelines::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_chimesdkmediapipelines::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_chimesdkmediapipelines::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_chimesdkmediapipelines::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkmediapipelines`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/chimesdkmediapipelines/src/config/endpoint.rs b/sdk/chimesdkmediapipelines/src/config/endpoint.rs index 80b5baf8d9b5..249d6f065b5c 100644 --- a/sdk/chimesdkmediapipelines/src/config/endpoint.rs +++ b/sdk/chimesdkmediapipelines/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -519,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -538,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -575,7 +548,6 @@ mod test { /// Missing region #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -584,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Chime SDK Media Pipelines +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -620,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/chimesdkmeetings/src/config.rs b/sdk/chimesdkmeetings/src/config.rs index 98a78fbf3b37..8bf5b3e3d345 100644 --- a/sdk/chimesdkmeetings/src/config.rs +++ b/sdk/chimesdkmeetings/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkmeetings`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_chimesdkmeetings::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_chimesdkmeetings::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_chimesdkmeetings::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_chimesdkmeetings::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_chimesdkmeetings::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkmeetings`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/chimesdkmeetings/src/config/endpoint.rs b/sdk/chimesdkmeetings/src/config/endpoint.rs index 1ce3754e4d65..3b8c05d6dc78 100644 --- a/sdk/chimesdkmeetings/src/config/endpoint.rs +++ b/sdk/chimesdkmeetings/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Chime SDK Meetings +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/chimesdkmessaging/src/config.rs b/sdk/chimesdkmessaging/src/config.rs index c0f6a3813ba7..30588f8e5888 100644 --- a/sdk/chimesdkmessaging/src/config.rs +++ b/sdk/chimesdkmessaging/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkmessaging`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_chimesdkmessaging::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_chimesdkmessaging::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_chimesdkmessaging::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_chimesdkmessaging::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_chimesdkmessaging::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkmessaging`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/chimesdkmessaging/src/config/endpoint.rs b/sdk/chimesdkmessaging/src/config/endpoint.rs index 2f35113a8b01..a03253a7de31 100644 --- a/sdk/chimesdkmessaging/src/config/endpoint.rs +++ b/sdk/chimesdkmessaging/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Chime SDK Messaging +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/chimesdkvoice/src/config.rs b/sdk/chimesdkvoice/src/config.rs index a1309e8cac4b..b05b65036811 100644 --- a/sdk/chimesdkvoice/src/config.rs +++ b/sdk/chimesdkvoice/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkvoice`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_chimesdkvoice::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_chimesdkvoice::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_chimesdkvoice::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_chimesdkvoice::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_chimesdkvoice::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_chimesdkvoice`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/chimesdkvoice/src/config/endpoint.rs b/sdk/chimesdkvoice/src/config/endpoint.rs index fcca134ba835..73a869713466 100644 --- a/sdk/chimesdkvoice/src/config/endpoint.rs +++ b/sdk/chimesdkvoice/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Chime SDK Voice +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cleanrooms/src/config.rs b/sdk/cleanrooms/src/config.rs index fcd1c6097274..24bc92c56eda 100644 --- a/sdk/cleanrooms/src/config.rs +++ b/sdk/cleanrooms/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cleanrooms`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cleanrooms::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cleanrooms::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cleanrooms::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cleanrooms::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cleanrooms::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cleanrooms`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cleanrooms/src/config/endpoint.rs b/sdk/cleanrooms/src/config/endpoint.rs index 305416d82005..93ee61044710 100644 --- a/sdk/cleanrooms/src/config/endpoint.rs +++ b/sdk/cleanrooms/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Clean Rooms Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloud9/src/config.rs b/sdk/cloud9/src/config.rs index d15b4575beb9..c8d10bde4aba 100644 --- a/sdk/cloud9/src/config.rs +++ b/sdk/cloud9/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloud9`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloud9::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloud9::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloud9::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloud9::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloud9::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloud9`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloud9/src/config/endpoint.rs b/sdk/cloud9/src/config/endpoint.rs index 38ba499970d5..d496700efe90 100644 --- a/sdk/cloud9/src/config/endpoint.rs +++ b/sdk/cloud9/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Cloud9 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudcontrol/src/config.rs b/sdk/cloudcontrol/src/config.rs index 7f1fb1d66eaa..df21650f53ab 100644 --- a/sdk/cloudcontrol/src/config.rs +++ b/sdk/cloudcontrol/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudcontrol`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudcontrol::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudcontrol::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudcontrol::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudcontrol::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudcontrol::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudcontrol`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudcontrol/src/config/endpoint.rs b/sdk/cloudcontrol/src/config/endpoint.rs index 43a9aca77c3f..bc36e2ffc7e7 100644 --- a/sdk/cloudcontrol/src/config/endpoint.rs +++ b/sdk/cloudcontrol/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Cloud Control API +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/clouddirectory/src/config.rs b/sdk/clouddirectory/src/config.rs index 8ae919fdd037..e4d6d1e5ba82 100644 --- a/sdk/clouddirectory/src/config.rs +++ b/sdk/clouddirectory/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_clouddirectory`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_clouddirectory::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_clouddirectory::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_clouddirectory::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_clouddirectory::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_clouddirectory::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_clouddirectory`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/clouddirectory/src/config/endpoint.rs b/sdk/clouddirectory/src/config/endpoint.rs index bd492616c7c8..b0268c154d31 100644 --- a/sdk/clouddirectory/src/config/endpoint.rs +++ b/sdk/clouddirectory/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudDirectory +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudformation/src/config.rs b/sdk/cloudformation/src/config.rs index 6e08bcce8c51..d12213cbbe0a 100644 --- a/sdk/cloudformation/src/config.rs +++ b/sdk/cloudformation/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudformation`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudformation::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudformation::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudformation::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudformation::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudformation::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudformation`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudformation/src/config/endpoint.rs b/sdk/cloudformation/src/config/endpoint.rs index f6ceb70dda6d..92664284aaae 100644 --- a/sdk/cloudformation/src/config/endpoint.rs +++ b/sdk/cloudformation/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CloudFormation +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudfront/src/config.rs b/sdk/cloudfront/src/config.rs index e55f828426e3..0a992492cddc 100644 --- a/sdk/cloudfront/src/config.rs +++ b/sdk/cloudfront/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudfront`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudfront::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudfront::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudfront::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudfront::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudfront::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudfront`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudfront/src/config/endpoint.rs b/sdk/cloudfront/src/config/endpoint.rs index 7df751f68612..baf0cbb73c9b 100644 --- a/sdk/cloudfront/src/config/endpoint.rs +++ b/sdk/cloudfront/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region aws-global with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -71,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -92,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -123,7 +120,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -144,7 +140,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -175,7 +170,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -206,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -227,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -248,7 +240,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -269,7 +260,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -300,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -321,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -342,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -363,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -384,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -403,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -424,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -440,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -461,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -480,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -501,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -517,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -538,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -558,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -577,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -594,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -614,7 +588,6 @@ mod test { /// Missing region #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -623,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudFront +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -659,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudhsm/src/config.rs b/sdk/cloudhsm/src/config.rs index d4437b4e82bf..5413d2fd7a54 100644 --- a/sdk/cloudhsm/src/config.rs +++ b/sdk/cloudhsm/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudhsm`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudhsm::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudhsm::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudhsm::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudhsm::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudhsm::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudhsm`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudhsm/src/config/endpoint.rs b/sdk/cloudhsm/src/config/endpoint.rs index cfa09c5b94a5..bb6ed9b41b4f 100644 --- a/sdk/cloudhsm/src/config/endpoint.rs +++ b/sdk/cloudhsm/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudHSM +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudhsmv2/src/config.rs b/sdk/cloudhsmv2/src/config.rs index 7938d3635ff8..2f1be4790515 100644 --- a/sdk/cloudhsmv2/src/config.rs +++ b/sdk/cloudhsmv2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudhsmv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudhsmv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudhsmv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudhsmv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudhsmv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudhsmv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudhsmv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudhsmv2/src/config/endpoint.rs b/sdk/cloudhsmv2/src/config/endpoint.rs index 140e9b8b1961..83b16b5939e1 100644 --- a/sdk/cloudhsmv2/src/config/endpoint.rs +++ b/sdk/cloudhsmv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -876,7 +835,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -895,7 +853,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -912,7 +869,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -932,7 +888,6 @@ mod test { /// Missing region #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -941,6 +896,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CloudHSM V2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -977,27 +996,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudsearch/src/config.rs b/sdk/cloudsearch/src/config.rs index df4c37006946..df9bbcdfc3c2 100644 --- a/sdk/cloudsearch/src/config.rs +++ b/sdk/cloudsearch/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudsearch`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudsearch::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudsearch::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudsearch::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudsearch::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudsearch::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudsearch`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudsearch/src/config/endpoint.rs b/sdk/cloudsearch/src/config/endpoint.rs index d06c62269b84..086e141088c2 100644 --- a/sdk/cloudsearch/src/config/endpoint.rs +++ b/sdk/cloudsearch/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -624,7 +595,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -643,7 +613,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -660,7 +629,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -680,7 +648,6 @@ mod test { /// Missing region #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -689,6 +656,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudSearch +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -725,27 +756,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudsearchdomain/src/config.rs b/sdk/cloudsearchdomain/src/config.rs index b14876a2f321..f6c1700028c5 100644 --- a/sdk/cloudsearchdomain/src/config.rs +++ b/sdk/cloudsearchdomain/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudsearchdomain`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudsearchdomain::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudsearchdomain::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudsearchdomain::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudsearchdomain::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudsearchdomain::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudsearchdomain`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudsearchdomain/src/config/endpoint.rs b/sdk/cloudsearchdomain/src/config/endpoint.rs index f518a3da5b91..2db30af68285 100644 --- a/sdk/cloudsearchdomain/src/config/endpoint.rs +++ b/sdk/cloudsearchdomain/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudSearch Domain +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudtrail/src/config.rs b/sdk/cloudtrail/src/config.rs index 3c264e21f592..526d897dd77e 100644 --- a/sdk/cloudtrail/src/config.rs +++ b/sdk/cloudtrail/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudtrail`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudtrail::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudtrail::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudtrail::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudtrail::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudtrail::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudtrail`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudtrail/src/config/endpoint.rs b/sdk/cloudtrail/src/config/endpoint.rs index 57cdc809cce7..50bb1de8553b 100644 --- a/sdk/cloudtrail/src/config/endpoint.rs +++ b/sdk/cloudtrail/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CloudTrail +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudtraildata/src/config.rs b/sdk/cloudtraildata/src/config.rs index 265226a06d2c..9efa16b35b0b 100644 --- a/sdk/cloudtraildata/src/config.rs +++ b/sdk/cloudtraildata/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudtraildata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudtraildata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudtraildata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudtraildata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudtraildata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudtraildata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudtraildata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudtraildata/src/config/endpoint.rs b/sdk/cloudtraildata/src/config/endpoint.rs index f6f66159a0df..d1885bc7aa16 100644 --- a/sdk/cloudtraildata/src/config/endpoint.rs +++ b/sdk/cloudtraildata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CloudTrail Data Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudwatch/src/config.rs b/sdk/cloudwatch/src/config.rs index 4f5da7fa5e2e..c755177c29ff 100644 --- a/sdk/cloudwatch/src/config.rs +++ b/sdk/cloudwatch/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudwatch`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudwatch::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudwatch::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudwatch::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudwatch::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudwatch::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudwatch`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudwatch/src/config/endpoint.rs b/sdk/cloudwatch/src/config/endpoint.rs index ec6d38939719..50c5d55bb9cc 100644 --- a/sdk/cloudwatch/src/config/endpoint.rs +++ b/sdk/cloudwatch/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudWatch +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudwatchevents/src/config.rs b/sdk/cloudwatchevents/src/config.rs index 63b8efdaf449..36bc884334e4 100644 --- a/sdk/cloudwatchevents/src/config.rs +++ b/sdk/cloudwatchevents/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudwatchevents`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudwatchevents::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudwatchevents::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudwatchevents::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudwatchevents::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudwatchevents::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudwatchevents`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudwatchevents/src/config/endpoint.rs b/sdk/cloudwatchevents/src/config/endpoint.rs index 44be81037f5c..e09dcd49cf72 100644 --- a/sdk/cloudwatchevents/src/config/endpoint.rs +++ b/sdk/cloudwatchevents/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudWatch Events +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cloudwatchlogs/src/config.rs b/sdk/cloudwatchlogs/src/config.rs index 1725a291c593..17e75e77efcd 100644 --- a/sdk/cloudwatchlogs/src/config.rs +++ b/sdk/cloudwatchlogs/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudwatchlogs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cloudwatchlogs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cloudwatchlogs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cloudwatchlogs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cloudwatchlogs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cloudwatchlogs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cloudwatchlogs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cloudwatchlogs/src/config/endpoint.rs b/sdk/cloudwatchlogs/src/config/endpoint.rs index 19145875ea8d..c49d5a5fe576 100644 --- a/sdk/cloudwatchlogs/src/config/endpoint.rs +++ b/sdk/cloudwatchlogs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudWatch Logs +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codeartifact/src/config.rs b/sdk/codeartifact/src/config.rs index 05706fe7c75e..864e07e6b87a 100644 --- a/sdk/codeartifact/src/config.rs +++ b/sdk/codeartifact/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codeartifact`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codeartifact::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codeartifact::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codeartifact::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codeartifact::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codeartifact::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codeartifact`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codeartifact/src/config/endpoint.rs b/sdk/codeartifact/src/config/endpoint.rs index 0be0c493e05d..d4265f56d316 100644 --- a/sdk/codeartifact/src/config/endpoint.rs +++ b/sdk/codeartifact/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -687,7 +655,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -706,7 +673,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +689,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -743,7 +708,6 @@ mod test { /// Missing region #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -752,6 +716,70 @@ mod test { } } +/// Endpoint resolver trait specific to CodeArtifact +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -788,27 +816,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codebuild/src/config.rs b/sdk/codebuild/src/config.rs index a1f366e4f06c..6830cce9256e 100644 --- a/sdk/codebuild/src/config.rs +++ b/sdk/codebuild/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codebuild`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codebuild::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codebuild::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codebuild::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codebuild::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codebuild::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codebuild`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codebuild/src/config/endpoint.rs b/sdk/codebuild/src/config/endpoint.rs index 13ce57287086..4999272c98f6 100644 --- a/sdk/codebuild/src/config/endpoint.rs +++ b/sdk/codebuild/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CodeBuild +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codecatalyst/src/config.rs b/sdk/codecatalyst/src/config.rs index 43b208a8f584..f2b711ee1084 100644 --- a/sdk/codecatalyst/src/config.rs +++ b/sdk/codecatalyst/src/config.rs @@ -234,63 +234,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codecatalyst`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codecatalyst::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codecatalyst::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codecatalyst::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codecatalyst::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codecatalyst::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codecatalyst`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -943,11 +926,10 @@ impl ServiceRuntimePlugin { runtime_components.push_auth_scheme(::aws_smithy_runtime_api::client::auth::SharedAuthScheme::new( ::aws_smithy_runtime::client::auth::http::BearerAuthScheme::new(), )); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1135,7 +1117,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codecatalyst/src/config/endpoint.rs b/sdk/codecatalyst/src/config/endpoint.rs index a68d1dc93447..64bf8fc5c87c 100644 --- a/sdk/codecatalyst/src/config/endpoint.rs +++ b/sdk/codecatalyst/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// Override endpoint #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint("https://test.codecatalyst.global.api.aws".to_string()) .build() @@ -28,7 +28,6 @@ mod test { /// Default endpoint (region not set) #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -44,7 +43,6 @@ mod test { /// Default FIPS endpoint (region not set) #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().use_fips(true).build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -60,7 +58,6 @@ mod test { /// Default endpoint (region: aws-global) #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .build() @@ -79,7 +76,6 @@ mod test { /// Default FIPS endpoint (region: aws-global) #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -99,7 +95,6 @@ mod test { /// Default endpoint for a valid home region (region: us-west-2) #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .build() @@ -118,7 +113,6 @@ mod test { /// Default FIPS endpoint for a valid home region (region: us-west-2) #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -138,7 +132,6 @@ mod test { /// Default endpoint for an unavailable home region (region: us-east-1) #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .build() @@ -157,7 +150,6 @@ mod test { /// Default FIPS endpoint for an unavailable home region (region: us-east-1) #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -175,6 +167,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CodeCatalyst +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -205,27 +261,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codecommit/src/config.rs b/sdk/codecommit/src/config.rs index 4f3342f5e6a5..6b9c21620119 100644 --- a/sdk/codecommit/src/config.rs +++ b/sdk/codecommit/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codecommit`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codecommit::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codecommit::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codecommit::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codecommit::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codecommit::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codecommit`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codecommit/src/config/endpoint.rs b/sdk/codecommit/src/config/endpoint.rs index e7da450b6012..724294f3c8eb 100644 --- a/sdk/codecommit/src/config/endpoint.rs +++ b/sdk/codecommit/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CodeCommit +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codedeploy/src/config.rs b/sdk/codedeploy/src/config.rs index a26f3ccb699b..a2ebece86c09 100644 --- a/sdk/codedeploy/src/config.rs +++ b/sdk/codedeploy/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codedeploy`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codedeploy::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codedeploy::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codedeploy::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codedeploy::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codedeploy::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codedeploy`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codedeploy/src/config/endpoint.rs b/sdk/codedeploy/src/config/endpoint.rs index 74e470b2789a..df6bb6b2f511 100644 --- a/sdk/codedeploy/src/config/endpoint.rs +++ b/sdk/codedeploy/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CodeDeploy +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codeguruprofiler/src/config.rs b/sdk/codeguruprofiler/src/config.rs index 2c52f0ec762f..aefd03e48935 100644 --- a/sdk/codeguruprofiler/src/config.rs +++ b/sdk/codeguruprofiler/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codeguruprofiler`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codeguruprofiler::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codeguruprofiler::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codeguruprofiler::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codeguruprofiler::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codeguruprofiler::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codeguruprofiler`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codeguruprofiler/src/config/endpoint.rs b/sdk/codeguruprofiler/src/config/endpoint.rs index a9ff07ce7c96..8598f83d0846 100644 --- a/sdk/codeguruprofiler/src/config/endpoint.rs +++ b/sdk/codeguruprofiler/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CodeGuru Profiler +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codegurureviewer/src/config.rs b/sdk/codegurureviewer/src/config.rs index 57a53bbc89c5..d7f86a75d503 100644 --- a/sdk/codegurureviewer/src/config.rs +++ b/sdk/codegurureviewer/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codegurureviewer`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codegurureviewer::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codegurureviewer::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codegurureviewer::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codegurureviewer::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codegurureviewer::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codegurureviewer`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codegurureviewer/src/config/endpoint.rs b/sdk/codegurureviewer/src/config/endpoint.rs index 7044eeff5e75..6351566e4146 100644 --- a/sdk/codegurureviewer/src/config/endpoint.rs +++ b/sdk/codegurureviewer/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -624,7 +595,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -643,7 +613,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -660,7 +629,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -680,7 +648,6 @@ mod test { /// Missing region #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -689,6 +656,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CodeGuru Reviewer +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -725,27 +756,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codegurusecurity/src/config.rs b/sdk/codegurusecurity/src/config.rs index 36d546b5641b..39ebe13fc3c4 100644 --- a/sdk/codegurusecurity/src/config.rs +++ b/sdk/codegurusecurity/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codegurusecurity`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codegurusecurity::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codegurusecurity::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codegurusecurity::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codegurusecurity::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codegurusecurity::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codegurusecurity`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codegurusecurity/src/config/endpoint.rs b/sdk/codegurusecurity/src/config/endpoint.rs index 7257556696a3..2b3b73f8d406 100644 --- a/sdk/codegurusecurity/src/config/endpoint.rs +++ b/sdk/codegurusecurity/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CodeGuru Security +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codepipeline/src/config.rs b/sdk/codepipeline/src/config.rs index bbc4269350cb..737d27a6d53f 100644 --- a/sdk/codepipeline/src/config.rs +++ b/sdk/codepipeline/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codepipeline`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codepipeline::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codepipeline::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codepipeline::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codepipeline::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codepipeline::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codepipeline`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codepipeline/src/config/endpoint.rs b/sdk/codepipeline/src/config/endpoint.rs index fa43466cdb75..ba5549b7ac7e 100644 --- a/sdk/codepipeline/src/config/endpoint.rs +++ b/sdk/codepipeline/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CodePipeline +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codestar/src/config.rs b/sdk/codestar/src/config.rs index 7ae00ebbabd6..c6f446c440ea 100644 --- a/sdk/codestar/src/config.rs +++ b/sdk/codestar/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codestar`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codestar::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codestar::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codestar::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codestar::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codestar::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codestar`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codestar/src/config/endpoint.rs b/sdk/codestar/src/config/endpoint.rs index fd6876417a6b..a34b03a99dfb 100644 --- a/sdk/codestar/src/config/endpoint.rs +++ b/sdk/codestar/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -687,7 +655,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -706,7 +673,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +689,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -743,7 +708,6 @@ mod test { /// Missing region #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -752,6 +716,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CodeStar +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -788,27 +816,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codestarconnections/src/config.rs b/sdk/codestarconnections/src/config.rs index a3331c3b4d87..fc1b4b830cff 100644 --- a/sdk/codestarconnections/src/config.rs +++ b/sdk/codestarconnections/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codestarconnections`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codestarconnections::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codestarconnections::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codestarconnections::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codestarconnections::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codestarconnections::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codestarconnections`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codestarconnections/src/config/endpoint.rs b/sdk/codestarconnections/src/config/endpoint.rs index b2305ec17dd0..b1601c08c7a4 100644 --- a/sdk/codestarconnections/src/config/endpoint.rs +++ b/sdk/codestarconnections/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CodeStar connections +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/codestarnotifications/src/config.rs b/sdk/codestarnotifications/src/config.rs index 117a8b8d619a..64e12bc7695c 100644 --- a/sdk/codestarnotifications/src/config.rs +++ b/sdk/codestarnotifications/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codestarnotifications`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_codestarnotifications::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_codestarnotifications::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_codestarnotifications::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_codestarnotifications::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_codestarnotifications::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_codestarnotifications`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/codestarnotifications/src/config/endpoint.rs b/sdk/codestarnotifications/src/config/endpoint.rs index 8e2b73f7ad1b..b529c1788a55 100644 --- a/sdk/codestarnotifications/src/config/endpoint.rs +++ b/sdk/codestarnotifications/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS CodeStar Notifications +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cognitoidentity/src/config.rs b/sdk/cognitoidentity/src/config.rs index 737e2e240d47..84aa04cf3d99 100644 --- a/sdk/cognitoidentity/src/config.rs +++ b/sdk/cognitoidentity/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cognitoidentity`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cognitoidentity::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cognitoidentity::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cognitoidentity::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cognitoidentity::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cognitoidentity::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cognitoidentity`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cognitoidentity/src/config/endpoint.rs b/sdk/cognitoidentity/src/config/endpoint.rs index cf49bab59101..9676893d7435 100644 --- a/sdk/cognitoidentity/src/config/endpoint.rs +++ b/sdk/cognitoidentity/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Cognito Identity +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cognitoidentityprovider/src/config.rs b/sdk/cognitoidentityprovider/src/config.rs index ea9a408ebf6d..54753ad20669 100644 --- a/sdk/cognitoidentityprovider/src/config.rs +++ b/sdk/cognitoidentityprovider/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cognitoidentityprovider`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cognitoidentityprovider::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cognitoidentityprovider::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cognitoidentityprovider::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cognitoidentityprovider::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cognitoidentityprovider::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cognitoidentityprovider`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cognitoidentityprovider/src/config/endpoint.rs b/sdk/cognitoidentityprovider/src/config/endpoint.rs index eaf0e09da12b..d00540e4553c 100644 --- a/sdk/cognitoidentityprovider/src/config/endpoint.rs +++ b/sdk/cognitoidentityprovider/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -876,7 +835,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -895,7 +853,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -912,7 +869,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -932,7 +888,6 @@ mod test { /// Missing region #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -941,6 +896,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Cognito Identity Provider +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -977,27 +996,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/cognitosync/src/config.rs b/sdk/cognitosync/src/config.rs index 4a49b0810874..df1179d98363 100644 --- a/sdk/cognitosync/src/config.rs +++ b/sdk/cognitosync/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cognitosync`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_cognitosync::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_cognitosync::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_cognitosync::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_cognitosync::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_cognitosync::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_cognitosync`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/cognitosync/src/config/endpoint.rs b/sdk/cognitosync/src/config/endpoint.rs index 82974c87de58..c6851ea6cccb 100644 --- a/sdk/cognitosync/src/config/endpoint.rs +++ b/sdk/cognitosync/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Cognito Sync +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/comprehend/src/config.rs b/sdk/comprehend/src/config.rs index 2495251cb3a9..3088845cc495 100644 --- a/sdk/comprehend/src/config.rs +++ b/sdk/comprehend/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_comprehend`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_comprehend::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_comprehend::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_comprehend::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_comprehend::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_comprehend::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_comprehend`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/comprehend/src/config/endpoint.rs b/sdk/comprehend/src/config/endpoint.rs index 8e6cd32a8ad0..d43e956a09b5 100644 --- a/sdk/comprehend/src/config/endpoint.rs +++ b/sdk/comprehend/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Comprehend +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/comprehendmedical/src/config.rs b/sdk/comprehendmedical/src/config.rs index c28e8f033968..7f0d6343c472 100644 --- a/sdk/comprehendmedical/src/config.rs +++ b/sdk/comprehendmedical/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_comprehendmedical`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_comprehendmedical::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_comprehendmedical::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_comprehendmedical::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_comprehendmedical::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_comprehendmedical::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_comprehendmedical`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/comprehendmedical/src/config/endpoint.rs b/sdk/comprehendmedical/src/config/endpoint.rs index 2057499da43c..dcf025e70592 100644 --- a/sdk/comprehendmedical/src/config/endpoint.rs +++ b/sdk/comprehendmedical/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Comprehend Medical +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/computeoptimizer/src/config.rs b/sdk/computeoptimizer/src/config.rs index 57d0a60ed05e..38875252be06 100644 --- a/sdk/computeoptimizer/src/config.rs +++ b/sdk/computeoptimizer/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_computeoptimizer`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_computeoptimizer::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_computeoptimizer::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_computeoptimizer::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_computeoptimizer::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_computeoptimizer::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_computeoptimizer`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/computeoptimizer/src/config/endpoint.rs b/sdk/computeoptimizer/src/config/endpoint.rs index 6c154ea874bf..15006c8eab92 100644 --- a/sdk/computeoptimizer/src/config/endpoint.rs +++ b/sdk/computeoptimizer/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -751,7 +716,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -771,7 +735,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -790,7 +753,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +769,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -827,7 +788,6 @@ mod test { /// Missing region #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -836,6 +796,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Compute Optimizer +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -872,27 +896,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/config/src/config.rs b/sdk/config/src/config.rs index eb771315f626..d98b45125bfe 100644 --- a/sdk/config/src/config.rs +++ b/sdk/config/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_config`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_config::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_config::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_config::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_config::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_config::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_config`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/config/src/config/endpoint.rs b/sdk/config/src/config/endpoint.rs index 50b000577318..38bfc24d8c1d 100644 --- a/sdk/config/src/config/endpoint.rs +++ b/sdk/config/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Config +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/connect/src/config.rs b/sdk/connect/src/config.rs index 08c3cdfc5f70..5ec22869481f 100644 --- a/sdk/connect/src/config.rs +++ b/sdk/connect/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connect`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_connect::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_connect::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_connect::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_connect::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_connect::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connect`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/connect/src/config/endpoint.rs b/sdk/connect/src/config/endpoint.rs index d4120ae197a4..7e9a63daf214 100644 --- a/sdk/connect/src/config/endpoint.rs +++ b/sdk/connect/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -666,7 +635,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -685,7 +653,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -702,7 +669,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -722,7 +688,6 @@ mod test { /// Missing region #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -731,6 +696,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Connect Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -767,27 +796,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/connectcampaigns/src/config.rs b/sdk/connectcampaigns/src/config.rs index 00795cf973ba..e7e22dbd23a7 100644 --- a/sdk/connectcampaigns/src/config.rs +++ b/sdk/connectcampaigns/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectcampaigns`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_connectcampaigns::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_connectcampaigns::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_connectcampaigns::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_connectcampaigns::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_connectcampaigns::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectcampaigns`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/connectcampaigns/src/config/endpoint.rs b/sdk/connectcampaigns/src/config/endpoint.rs index acdc1c730ae6..8dbdecee3b1e 100644 --- a/sdk/connectcampaigns/src/config/endpoint.rs +++ b/sdk/connectcampaigns/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -498,7 +475,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -517,7 +493,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -534,7 +509,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -554,7 +528,6 @@ mod test { /// Missing region #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -563,6 +536,70 @@ mod test { } } +/// Endpoint resolver trait specific to AmazonConnectCampaignService +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -599,27 +636,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/connectcases/src/config.rs b/sdk/connectcases/src/config.rs index 98748117eb43..60b0997d8fa2 100644 --- a/sdk/connectcases/src/config.rs +++ b/sdk/connectcases/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectcases`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_connectcases::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_connectcases::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_connectcases::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_connectcases::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_connectcases::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectcases`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/connectcases/src/config/endpoint.rs b/sdk/connectcases/src/config/endpoint.rs index c241664fc620..626d9c101226 100644 --- a/sdk/connectcases/src/config/endpoint.rs +++ b/sdk/connectcases/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Connect Cases +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/connectcontactlens/src/config.rs b/sdk/connectcontactlens/src/config.rs index 0ce07771fc36..b6f5523794a7 100644 --- a/sdk/connectcontactlens/src/config.rs +++ b/sdk/connectcontactlens/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectcontactlens`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_connectcontactlens::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_connectcontactlens::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_connectcontactlens::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_connectcontactlens::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_connectcontactlens::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectcontactlens`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/connectcontactlens/src/config/endpoint.rs b/sdk/connectcontactlens/src/config/endpoint.rs index cdafff4bbd9f..c8738aea930d 100644 --- a/sdk/connectcontactlens/src/config/endpoint.rs +++ b/sdk/connectcontactlens/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -582,7 +555,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -601,7 +573,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -618,7 +589,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -638,7 +608,6 @@ mod test { /// Missing region #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -647,6 +616,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Connect Contact Lens +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -683,27 +716,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/connectparticipant/src/config.rs b/sdk/connectparticipant/src/config.rs index 7af41160edae..bfc8ce411855 100644 --- a/sdk/connectparticipant/src/config.rs +++ b/sdk/connectparticipant/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectparticipant`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_connectparticipant::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_connectparticipant::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_connectparticipant::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_connectparticipant::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_connectparticipant::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_connectparticipant`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/connectparticipant/src/config/endpoint.rs b/sdk/connectparticipant/src/config/endpoint.rs index 440ea91cc27c..c885092f0bb8 100644 --- a/sdk/connectparticipant/src/config/endpoint.rs +++ b/sdk/connectparticipant/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Connect Participant Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/controltower/src/config.rs b/sdk/controltower/src/config.rs index e43b175e8fe2..a621a1186771 100644 --- a/sdk/controltower/src/config.rs +++ b/sdk/controltower/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_controltower`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_controltower::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_controltower::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_controltower::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_controltower::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_controltower::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_controltower`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/controltower/src/config/endpoint.rs b/sdk/controltower/src/config/endpoint.rs index b4ce06a58ddc..1b5cae0db5af 100644 --- a/sdk/controltower/src/config/endpoint.rs +++ b/sdk/controltower/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -658,7 +628,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -695,7 +663,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -735,7 +701,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -751,7 +716,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -772,7 +736,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -792,7 +755,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -811,7 +773,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -828,7 +789,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -848,7 +808,6 @@ mod test { /// Missing region #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -857,6 +816,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Control Tower +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -893,27 +916,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/costandusagereport/src/config.rs b/sdk/costandusagereport/src/config.rs index afc8a5207700..d9ea7a535fc4 100644 --- a/sdk/costandusagereport/src/config.rs +++ b/sdk/costandusagereport/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_costandusagereport`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_costandusagereport::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_costandusagereport::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_costandusagereport::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_costandusagereport::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_costandusagereport::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_costandusagereport`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/costandusagereport/src/config/endpoint.rs b/sdk/costandusagereport/src/config/endpoint.rs index f392082f663d..bd636b70ef82 100644 --- a/sdk/costandusagereport/src/config/endpoint.rs +++ b/sdk/costandusagereport/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Cost and Usage Report Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/costexplorer/src/config.rs b/sdk/costexplorer/src/config.rs index fa7ce8e22f21..a185b8813cac 100644 --- a/sdk/costexplorer/src/config.rs +++ b/sdk/costexplorer/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_costexplorer`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_costexplorer::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_costexplorer::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_costexplorer::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_costexplorer::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_costexplorer::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_costexplorer`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/costexplorer/src/config/endpoint.rs b/sdk/costexplorer/src/config/endpoint.rs index bb153d25a0bf..a9381fcd1429 100644 --- a/sdk/costexplorer/src/config/endpoint.rs +++ b/sdk/costexplorer/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -165,7 +160,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -186,7 +180,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -207,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -228,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -259,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -280,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -301,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -322,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -343,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -362,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -383,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -399,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -420,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -439,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -460,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -476,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -497,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -517,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -536,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -553,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -573,7 +548,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -582,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Cost Explorer Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -618,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/customerprofiles/src/config.rs b/sdk/customerprofiles/src/config.rs index 602408146da7..f17a3613ba46 100644 --- a/sdk/customerprofiles/src/config.rs +++ b/sdk/customerprofiles/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_customerprofiles`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_customerprofiles::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_customerprofiles::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_customerprofiles::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_customerprofiles::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_customerprofiles::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_customerprofiles`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/customerprofiles/src/config/endpoint.rs b/sdk/customerprofiles/src/config/endpoint.rs index 8e2b55f614bc..be5d347757d9 100644 --- a/sdk/customerprofiles/src/config/endpoint.rs +++ b/sdk/customerprofiles/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -624,7 +595,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -643,7 +613,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -660,7 +629,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -680,7 +648,6 @@ mod test { /// Missing region #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -689,6 +656,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Connect Customer Profiles +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -725,27 +756,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/databasemigration/src/config.rs b/sdk/databasemigration/src/config.rs index 260ed2991a2e..481198d411cb 100644 --- a/sdk/databasemigration/src/config.rs +++ b/sdk/databasemigration/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_databasemigration`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_databasemigration::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_databasemigration::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_databasemigration::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_databasemigration::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_databasemigration::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_databasemigration`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/databasemigration/src/config/endpoint.rs b/sdk/databasemigration/src/config/endpoint.rs index 7df0b7cf2074..7c460c9e7f2f 100644 --- a/sdk/databasemigration/src/config/endpoint.rs +++ b/sdk/databasemigration/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-iso-west-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(true) @@ -912,7 +870,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -931,7 +888,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -968,7 +923,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -989,7 +943,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1008,7 +961,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1024,7 +976,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1044,7 +995,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1063,7 +1013,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1080,7 +1029,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1100,7 +1048,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1109,6 +1056,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Database Migration Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1145,27 +1156,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/databrew/src/config.rs b/sdk/databrew/src/config.rs index 7f1217193d53..b905e73e1d8c 100644 --- a/sdk/databrew/src/config.rs +++ b/sdk/databrew/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_databrew`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_databrew::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_databrew::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_databrew::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_databrew::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_databrew::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_databrew`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/databrew/src/config/endpoint.rs b/sdk/databrew/src/config/endpoint.rs index a0e5571b4810..6c7bf2f30fb9 100644 --- a/sdk/databrew/src/config/endpoint.rs +++ b/sdk/databrew/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -876,7 +835,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -895,7 +853,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -912,7 +869,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -932,7 +888,6 @@ mod test { /// Missing region #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -941,6 +896,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Glue DataBrew +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -977,27 +996,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/dataexchange/src/config.rs b/sdk/dataexchange/src/config.rs index cf6316e67344..137553b12b20 100644 --- a/sdk/dataexchange/src/config.rs +++ b/sdk/dataexchange/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dataexchange`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_dataexchange::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_dataexchange::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_dataexchange::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_dataexchange::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_dataexchange::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dataexchange`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/dataexchange/src/config/endpoint.rs b/sdk/dataexchange/src/config/endpoint.rs index 1916cd71775c..9789edeaa5a0 100644 --- a/sdk/dataexchange/src/config/endpoint.rs +++ b/sdk/dataexchange/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Data Exchange +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/datapipeline/src/config.rs b/sdk/datapipeline/src/config.rs index d71b14659142..07c17855af82 100644 --- a/sdk/datapipeline/src/config.rs +++ b/sdk/datapipeline/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_datapipeline`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_datapipeline::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_datapipeline::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_datapipeline::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_datapipeline::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_datapipeline::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_datapipeline`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/datapipeline/src/config/endpoint.rs b/sdk/datapipeline/src/config/endpoint.rs index bbcc5dea2886..06309948455f 100644 --- a/sdk/datapipeline/src/config/endpoint.rs +++ b/sdk/datapipeline/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -519,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -538,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -575,7 +548,6 @@ mod test { /// Missing region #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -584,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Data Pipeline +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -620,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/datasync/src/config.rs b/sdk/datasync/src/config.rs index 015b72c51617..6d601615c05f 100644 --- a/sdk/datasync/src/config.rs +++ b/sdk/datasync/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_datasync`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_datasync::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_datasync::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_datasync::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_datasync::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_datasync::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_datasync`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/datasync/src/config/endpoint.rs b/sdk/datasync/src/config/endpoint.rs index c6a4f493d57d..7e9a117ae625 100644 --- a/sdk/datasync/src/config/endpoint.rs +++ b/sdk/datasync/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS DataSync +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/datazone/src/config.rs b/sdk/datazone/src/config.rs index 71227a0e1c37..fb97608a3237 100644 --- a/sdk/datazone/src/config.rs +++ b/sdk/datazone/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_datazone`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_datazone::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_datazone::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_datazone::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_datazone::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_datazone::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_datazone`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -957,11 +940,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1152,7 +1134,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/datazone/src/config/endpoint.rs b/sdk/datazone/src/config/endpoint.rs index 7de9f25304de..7fc4d3cc5ee5 100644 --- a/sdk/datazone/src/config/endpoint.rs +++ b/sdk/datazone/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -29,7 +29,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -49,7 +48,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -69,7 +67,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -89,7 +86,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -109,7 +105,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -129,7 +124,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -148,7 +142,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .endpoint("https://example.com".to_string()) @@ -166,7 +159,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -182,7 +174,6 @@ mod test { /// Missing region #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -191,6 +182,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon DataZone +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -221,27 +276,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/dax/src/config.rs b/sdk/dax/src/config.rs index 1a56df635cb0..77407fe12697 100644 --- a/sdk/dax/src/config.rs +++ b/sdk/dax/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dax`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_dax::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_dax::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_dax::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_dax::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_dax::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dax`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/dax/src/config/endpoint.rs b/sdk/dax/src/config/endpoint.rs index e407a103b4cc..96cd167449f2 100644 --- a/sdk/dax/src/config/endpoint.rs +++ b/sdk/dax/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -708,7 +675,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -727,7 +693,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -744,7 +709,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -764,7 +728,6 @@ mod test { /// Missing region #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -773,6 +736,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon DynamoDB Accelerator (DAX) +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -809,27 +836,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/detective/src/config.rs b/sdk/detective/src/config.rs index 593550e21850..a116bd38b311 100644 --- a/sdk/detective/src/config.rs +++ b/sdk/detective/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_detective`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_detective::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_detective::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_detective::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_detective::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_detective::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_detective`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/detective/src/config/endpoint.rs b/sdk/detective/src/config/endpoint.rs index 00883a66f8fc..0e10b8caaf8b 100644 --- a/sdk/detective/src/config/endpoint.rs +++ b/sdk/detective/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Detective +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/devicefarm/src/config.rs b/sdk/devicefarm/src/config.rs index 2b902fc66d3a..eebf8648bd8a 100644 --- a/sdk/devicefarm/src/config.rs +++ b/sdk/devicefarm/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_devicefarm`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_devicefarm::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_devicefarm::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_devicefarm::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_devicefarm::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_devicefarm::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_devicefarm`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/devicefarm/src/config/endpoint.rs b/sdk/devicefarm/src/config/endpoint.rs index e117a8cbb26c..e393f3d520b6 100644 --- a/sdk/devicefarm/src/config/endpoint.rs +++ b/sdk/devicefarm/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Device Farm +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/devopsguru/src/config.rs b/sdk/devopsguru/src/config.rs index 3003c71802d1..5e2bcf456bf1 100644 --- a/sdk/devopsguru/src/config.rs +++ b/sdk/devopsguru/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_devopsguru`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_devopsguru::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_devopsguru::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_devopsguru::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_devopsguru::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_devopsguru::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_devopsguru`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/devopsguru/src/config/endpoint.rs b/sdk/devopsguru/src/config/endpoint.rs index 51dc446e29e3..de9c19701900 100644 --- a/sdk/devopsguru/src/config/endpoint.rs +++ b/sdk/devopsguru/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon DevOps Guru +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/directconnect/src/config.rs b/sdk/directconnect/src/config.rs index 3db51871328f..f507a07843c3 100644 --- a/sdk/directconnect/src/config.rs +++ b/sdk/directconnect/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_directconnect`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_directconnect::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_directconnect::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_directconnect::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_directconnect::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_directconnect::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_directconnect`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/directconnect/src/config/endpoint.rs b/sdk/directconnect/src/config/endpoint.rs index a5b26d0f1656..73854b77bc77 100644 --- a/sdk/directconnect/src/config/endpoint.rs +++ b/sdk/directconnect/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Direct Connect +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/directory/src/config.rs b/sdk/directory/src/config.rs index 5f03c4df4de0..1afea587c757 100644 --- a/sdk/directory/src/config.rs +++ b/sdk/directory/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_directory`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_directory::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_directory::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_directory::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_directory::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_directory::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_directory`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/directory/src/config/endpoint.rs b/sdk/directory/src/config/endpoint.rs index 5a3957928c6f..4994b360cdc9 100644 --- a/sdk/directory/src/config/endpoint.rs +++ b/sdk/directory/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Directory Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/dlm/src/config.rs b/sdk/dlm/src/config.rs index c9596125f2ae..d1449d3af7ef 100644 --- a/sdk/dlm/src/config.rs +++ b/sdk/dlm/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dlm`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_dlm::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_dlm::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_dlm::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_dlm::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_dlm::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dlm`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/dlm/src/config/endpoint.rs b/sdk/dlm/src/config/endpoint.rs index fa5c601ed1c7..16f2f7ee3655 100644 --- a/sdk/dlm/src/config/endpoint.rs +++ b/sdk/dlm/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Data Lifecycle Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/docdb/src/config.rs b/sdk/docdb/src/config.rs index 2f2a44cdc39b..94609a2c00ba 100644 --- a/sdk/docdb/src/config.rs +++ b/sdk/docdb/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_docdb`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_docdb::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_docdb::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_docdb::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_docdb::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_docdb::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_docdb`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/docdb/src/config/endpoint.rs b/sdk/docdb/src/config/endpoint.rs index b7d06d90ca29..fd63901341c5 100644 --- a/sdk/docdb/src/config/endpoint.rs +++ b/sdk/docdb/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -931,7 +888,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -968,7 +923,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1008,7 +961,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1024,7 +976,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1044,7 +995,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1063,7 +1013,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1080,7 +1029,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1100,7 +1048,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1109,6 +1056,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon DocumentDB with MongoDB compatibility +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1145,27 +1156,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/docdbelastic/src/config.rs b/sdk/docdbelastic/src/config.rs index 44728d57745d..d7a002c11945 100644 --- a/sdk/docdbelastic/src/config.rs +++ b/sdk/docdbelastic/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_docdbelastic`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_docdbelastic::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_docdbelastic::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_docdbelastic::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_docdbelastic::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_docdbelastic::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_docdbelastic`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/docdbelastic/src/config/endpoint.rs b/sdk/docdbelastic/src/config/endpoint.rs index c5855342e988..a286ed4a9120 100644 --- a/sdk/docdbelastic/src/config/endpoint.rs +++ b/sdk/docdbelastic/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon DocumentDB Elastic Clusters +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/drs/src/config.rs b/sdk/drs/src/config.rs index fa164bdaed86..f13f1b4e7b47 100644 --- a/sdk/drs/src/config.rs +++ b/sdk/drs/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_drs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_drs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_drs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_drs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_drs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_drs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_drs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/drs/src/config/endpoint.rs b/sdk/drs/src/config/endpoint.rs index e630c2616a25..b68eb00213d0 100644 --- a/sdk/drs/src/config/endpoint.rs +++ b/sdk/drs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to Elastic Disaster Recovery Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/dynamodb/src/config.rs b/sdk/dynamodb/src/config.rs index 0eeedd922052..1945ac94c559 100644 --- a/sdk/dynamodb/src/config.rs +++ b/sdk/dynamodb/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dynamodb`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_dynamodb::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_dynamodb::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_dynamodb::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_dynamodb::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_dynamodb::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dynamodb`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/dynamodb/src/config/endpoint.rs b/sdk/dynamodb/src/config/endpoint.rs index 5f357b5782c0..a0c2633b5592 100644 --- a/sdk/dynamodb/src/config/endpoint.rs +++ b/sdk/dynamodb/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region local with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("local".to_string()) .use_fips(false) @@ -397,7 +380,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -418,7 +400,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -439,7 +420,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -460,7 +440,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -481,7 +460,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -502,7 +480,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -523,7 +500,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -544,7 +520,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -565,7 +540,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -586,7 +560,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -607,7 +580,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -628,7 +600,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -649,7 +620,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -670,7 +640,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -691,7 +660,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -712,7 +680,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -733,7 +700,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -754,7 +720,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -775,7 +740,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -796,7 +760,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -817,7 +780,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -838,7 +800,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -859,7 +820,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -880,7 +840,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -901,7 +860,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -922,7 +880,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -941,7 +898,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -962,7 +918,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -978,7 +933,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -999,7 +953,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1018,7 +971,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1039,7 +991,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1055,7 +1006,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1075,7 +1025,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1094,7 +1043,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1111,7 +1059,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1131,7 +1078,6 @@ mod test { /// Missing region #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1140,6 +1086,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon DynamoDB +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1176,27 +1186,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/dynamodbstreams/src/config.rs b/sdk/dynamodbstreams/src/config.rs index 1f42e641b779..f57a64587457 100644 --- a/sdk/dynamodbstreams/src/config.rs +++ b/sdk/dynamodbstreams/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dynamodbstreams`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_dynamodbstreams::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_dynamodbstreams::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_dynamodbstreams::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_dynamodbstreams::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_dynamodbstreams::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_dynamodbstreams`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/dynamodbstreams/src/config/endpoint.rs b/sdk/dynamodbstreams/src/config/endpoint.rs index 49b586cdc9e1..7908c59c06c9 100644 --- a/sdk/dynamodbstreams/src/config/endpoint.rs +++ b/sdk/dynamodbstreams/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region local with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("local".to_string()) .use_fips(false) @@ -376,7 +360,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -397,7 +380,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -418,7 +400,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -439,7 +420,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -460,7 +440,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -481,7 +460,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -502,7 +480,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -523,7 +500,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -544,7 +520,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -565,7 +540,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -586,7 +560,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -607,7 +580,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -628,7 +600,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -649,7 +620,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -670,7 +640,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -691,7 +660,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -712,7 +680,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -733,7 +700,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -754,7 +720,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -775,7 +740,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -796,7 +760,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -817,7 +780,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -836,7 +798,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -857,7 +818,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -873,7 +833,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -894,7 +853,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -913,7 +871,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -934,7 +891,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -950,7 +906,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -970,7 +925,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -989,7 +943,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1006,7 +959,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1026,7 +978,6 @@ mod test { /// Missing region #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1035,6 +986,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon DynamoDB Streams +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1071,27 +1086,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ebs/src/config.rs b/sdk/ebs/src/config.rs index 218c32c03d3d..5dbafc936038 100644 --- a/sdk/ebs/src/config.rs +++ b/sdk/ebs/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ebs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ebs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ebs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ebs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ebs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ebs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ebs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ebs/src/config/endpoint.rs b/sdk/ebs/src/config/endpoint.rs index 68b1e74cbb18..645398f1c6ce 100644 --- a/sdk/ebs/src/config/endpoint.rs +++ b/sdk/ebs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elastic Block Store +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ec2/src/config.rs b/sdk/ec2/src/config.rs index c736d0ab7c22..f91fdb44b3a9 100644 --- a/sdk/ec2/src/config.rs +++ b/sdk/ec2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ec2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ec2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ec2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ec2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ec2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ec2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ec2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ec2/src/config/endpoint.rs b/sdk/ec2/src/config/endpoint.rs index 7a80caeb8cab..67991de83fb5 100644 --- a/sdk/ec2/src/config/endpoint.rs +++ b/sdk/ec2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -891,7 +850,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -912,7 +870,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -933,7 +890,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -954,7 +910,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -975,7 +930,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -994,7 +948,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1015,7 +968,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1031,7 +983,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1052,7 +1003,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1071,7 +1021,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1092,7 +1041,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1108,7 +1056,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1128,7 +1075,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1147,7 +1093,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1164,7 +1109,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1184,7 +1128,6 @@ mod test { /// Missing region #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1193,6 +1136,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elastic Compute Cloud +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1229,27 +1236,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ec2instanceconnect/src/config.rs b/sdk/ec2instanceconnect/src/config.rs index a80bada56d26..c1cc9a6aa736 100644 --- a/sdk/ec2instanceconnect/src/config.rs +++ b/sdk/ec2instanceconnect/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ec2instanceconnect`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ec2instanceconnect::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ec2instanceconnect::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ec2instanceconnect::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ec2instanceconnect::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ec2instanceconnect::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ec2instanceconnect`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ec2instanceconnect/src/config/endpoint.rs b/sdk/ec2instanceconnect/src/config/endpoint.rs index f94f4e90d3cb..6a645269cca8 100644 --- a/sdk/ec2instanceconnect/src/config/endpoint.rs +++ b/sdk/ec2instanceconnect/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS EC2 Instance Connect +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ecr/src/config.rs b/sdk/ecr/src/config.rs index 7a5a7726ac3a..3ac5346dccb3 100644 --- a/sdk/ecr/src/config.rs +++ b/sdk/ecr/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ecr`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ecr::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ecr::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ecr::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ecr::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ecr::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ecr`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ecr/src/config/endpoint.rs b/sdk/ecr/src/config/endpoint.rs index efd4803317fa..a169d7ec66f0 100644 --- a/sdk/ecr/src/config/endpoint.rs +++ b/sdk/ecr/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon EC2 Container Registry +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ecrpublic/src/config.rs b/sdk/ecrpublic/src/config.rs index da6a8c95508c..d4f59c6c027b 100644 --- a/sdk/ecrpublic/src/config.rs +++ b/sdk/ecrpublic/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ecrpublic`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ecrpublic::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ecrpublic::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ecrpublic::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ecrpublic::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ecrpublic::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ecrpublic`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ecrpublic/src/config/endpoint.rs b/sdk/ecrpublic/src/config/endpoint.rs index a973a47ad749..2653f3a5b1ca 100644 --- a/sdk/ecrpublic/src/config/endpoint.rs +++ b/sdk/ecrpublic/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elastic Container Registry Public +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ecs/src/config.rs b/sdk/ecs/src/config.rs index f8e031eeee3f..164fc615c418 100644 --- a/sdk/ecs/src/config.rs +++ b/sdk/ecs/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ecs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ecs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ecs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ecs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ecs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ecs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ecs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ecs/src/config/endpoint.rs b/sdk/ecs/src/config/endpoint.rs index 61c81510262c..e42fd303c856 100644 --- a/sdk/ecs/src/config/endpoint.rs +++ b/sdk/ecs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon EC2 Container Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/efs/src/config.rs b/sdk/efs/src/config.rs index 4d0e90075802..a16bc9d68c8c 100644 --- a/sdk/efs/src/config.rs +++ b/sdk/efs/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_efs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_efs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_efs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_efs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_efs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_efs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_efs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/efs/src/config/endpoint.rs b/sdk/efs/src/config/endpoint.rs index b0e8d530e3d7..aaad2f546ef7 100644 --- a/sdk/efs/src/config/endpoint.rs +++ b/sdk/efs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region af-south-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-northeast-3 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ap-south-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region ap-southeast-2 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region ap-southeast-3 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-central-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-south-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region eu-west-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region eu-west-2 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region eu-west-3 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region me-south-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region sa-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -849,7 +810,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -891,7 +850,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -912,7 +870,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -933,7 +890,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +910,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -975,7 +930,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -996,7 +950,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1017,7 +970,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -1038,7 +990,6 @@ mod test { /// For region cn-northwest-1 with FIPS enabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -1059,7 +1010,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1080,7 +1030,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -1101,7 +1050,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1122,7 +1070,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1143,7 +1090,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1164,7 +1110,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -1185,7 +1130,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1206,7 +1150,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1227,7 +1170,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1248,7 +1190,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1269,7 +1210,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1288,7 +1228,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1304,7 +1243,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1325,7 +1263,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1346,7 +1283,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1365,7 +1301,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1381,7 +1316,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1401,7 +1335,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1420,7 +1353,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1437,7 +1369,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1457,7 +1388,6 @@ mod test { /// Missing region #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1466,6 +1396,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elastic File System +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1502,27 +1496,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/eks/src/config.rs b/sdk/eks/src/config.rs index ff44fe60e428..ee5fc789df92 100644 --- a/sdk/eks/src/config.rs +++ b/sdk/eks/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_eks`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_eks::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_eks::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_eks::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_eks::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_eks::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_eks`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/eks/src/config/endpoint.rs b/sdk/eks/src/config/endpoint.rs index a9a870566459..dd3ff582918c 100644 --- a/sdk/eks/src/config/endpoint.rs +++ b/sdk/eks/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elastic Kubernetes Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/elasticache/src/config.rs b/sdk/elasticache/src/config.rs index f39301b0d195..edbf2194af2f 100644 --- a/sdk/elasticache/src/config.rs +++ b/sdk/elasticache/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticache`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_elasticache::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_elasticache::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_elasticache::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_elasticache::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_elasticache::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticache`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/elasticache/src/config/endpoint.rs b/sdk/elasticache/src/config/endpoint.rs index 0c0a3c6e0e7b..07395f00526d 100644 --- a/sdk/elasticache/src/config/endpoint.rs +++ b/sdk/elasticache/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon ElastiCache +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/elasticbeanstalk/src/config.rs b/sdk/elasticbeanstalk/src/config.rs index 46570bfee9aa..1f6ebc45a6f5 100644 --- a/sdk/elasticbeanstalk/src/config.rs +++ b/sdk/elasticbeanstalk/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticbeanstalk`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_elasticbeanstalk::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_elasticbeanstalk::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_elasticbeanstalk::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_elasticbeanstalk::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_elasticbeanstalk::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticbeanstalk`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/elasticbeanstalk/src/config/endpoint.rs b/sdk/elasticbeanstalk/src/config/endpoint.rs index d95b3e77c7ad..1a08a24f66fd 100644 --- a/sdk/elasticbeanstalk/src/config/endpoint.rs +++ b/sdk/elasticbeanstalk/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elastic Beanstalk +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/elasticinference/src/config.rs b/sdk/elasticinference/src/config.rs index 55c7450eaaca..3e94dec0c5b2 100644 --- a/sdk/elasticinference/src/config.rs +++ b/sdk/elasticinference/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticinference`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_elasticinference::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_elasticinference::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_elasticinference::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_elasticinference::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_elasticinference::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticinference`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/elasticinference/src/config/endpoint.rs b/sdk/elasticinference/src/config/endpoint.rs index cc507b9b08f0..4b59f546f26a 100644 --- a/sdk/elasticinference/src/config/endpoint.rs +++ b/sdk/elasticinference/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elastic Inference +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/elasticloadbalancing/src/config.rs b/sdk/elasticloadbalancing/src/config.rs index f839798f08ae..419f0cac3b4a 100644 --- a/sdk/elasticloadbalancing/src/config.rs +++ b/sdk/elasticloadbalancing/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticloadbalancing`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_elasticloadbalancing::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_elasticloadbalancing::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_elasticloadbalancing::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_elasticloadbalancing::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_elasticloadbalancing::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticloadbalancing`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/elasticloadbalancing/src/config/endpoint.rs b/sdk/elasticloadbalancing/src/config/endpoint.rs index bf5df73c94a8..6c65c79d9927 100644 --- a/sdk/elasticloadbalancing/src/config/endpoint.rs +++ b/sdk/elasticloadbalancing/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Elastic Load Balancing +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/elasticloadbalancingv2/src/config.rs b/sdk/elasticloadbalancingv2/src/config.rs index 408d5e38dbfb..6f0e20245ee5 100644 --- a/sdk/elasticloadbalancingv2/src/config.rs +++ b/sdk/elasticloadbalancingv2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticloadbalancingv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_elasticloadbalancingv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_elasticloadbalancingv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_elasticloadbalancingv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_elasticloadbalancingv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_elasticloadbalancingv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticloadbalancingv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/elasticloadbalancingv2/src/config/endpoint.rs b/sdk/elasticloadbalancingv2/src/config/endpoint.rs index bf5df73c94a8..6c65c79d9927 100644 --- a/sdk/elasticloadbalancingv2/src/config/endpoint.rs +++ b/sdk/elasticloadbalancingv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Elastic Load Balancing +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/elasticsearch/src/config.rs b/sdk/elasticsearch/src/config.rs index b5ba4134a443..809e7a089890 100644 --- a/sdk/elasticsearch/src/config.rs +++ b/sdk/elasticsearch/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticsearch`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_elasticsearch::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_elasticsearch::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_elasticsearch::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_elasticsearch::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_elasticsearch::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elasticsearch`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/elasticsearch/src/config/endpoint.rs b/sdk/elasticsearch/src/config/endpoint.rs index d3ece45165d0..f6971a2f175a 100644 --- a/sdk/elasticsearch/src/config/endpoint.rs +++ b/sdk/elasticsearch/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elasticsearch Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/elastictranscoder/src/config.rs b/sdk/elastictranscoder/src/config.rs index 1ff12d6acdec..b1d872bc9092 100644 --- a/sdk/elastictranscoder/src/config.rs +++ b/sdk/elastictranscoder/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elastictranscoder`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_elastictranscoder::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_elastictranscoder::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_elastictranscoder::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_elastictranscoder::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_elastictranscoder::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_elastictranscoder`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/elastictranscoder/src/config/endpoint.rs b/sdk/elastictranscoder/src/config/endpoint.rs index ef7b8dc7b01e..692d348dac2c 100644 --- a/sdk/elastictranscoder/src/config/endpoint.rs +++ b/sdk/elastictranscoder/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -582,7 +555,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -601,7 +573,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -618,7 +589,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -638,7 +608,6 @@ mod test { /// Missing region #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -647,6 +616,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Elastic Transcoder +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -683,27 +716,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/emr/src/config.rs b/sdk/emr/src/config.rs index 77a799753662..4a529ad6cc68 100644 --- a/sdk/emr/src/config.rs +++ b/sdk/emr/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_emr`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_emr::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_emr::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_emr::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_emr::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_emr::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_emr`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/emr/src/config/endpoint.rs b/sdk/emr/src/config/endpoint.rs index e29bf543949d..4db91f24c039 100644 --- a/sdk/emr/src/config/endpoint.rs +++ b/sdk/emr/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -931,7 +888,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -968,7 +923,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1008,7 +961,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1024,7 +976,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1044,7 +995,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1063,7 +1013,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1080,7 +1029,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1100,7 +1048,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1109,6 +1056,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon EMR +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1145,27 +1156,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/emrcontainers/src/config.rs b/sdk/emrcontainers/src/config.rs index 409c9c880c7c..e22bfe5a5c41 100644 --- a/sdk/emrcontainers/src/config.rs +++ b/sdk/emrcontainers/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_emrcontainers`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_emrcontainers::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_emrcontainers::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_emrcontainers::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_emrcontainers::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_emrcontainers::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_emrcontainers`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/emrcontainers/src/config/endpoint.rs b/sdk/emrcontainers/src/config/endpoint.rs index 3c2296e14de7..e49d649fc16d 100644 --- a/sdk/emrcontainers/src/config/endpoint.rs +++ b/sdk/emrcontainers/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon EMR Containers +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/emrserverless/src/config.rs b/sdk/emrserverless/src/config.rs index 418e056e5c38..a24981cd9edc 100644 --- a/sdk/emrserverless/src/config.rs +++ b/sdk/emrserverless/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_emrserverless`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_emrserverless::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_emrserverless::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_emrserverless::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_emrserverless::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_emrserverless::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_emrserverless`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/emrserverless/src/config/endpoint.rs b/sdk/emrserverless/src/config/endpoint.rs index c0d3d3b0db68..591954f9bf86 100644 --- a/sdk/emrserverless/src/config/endpoint.rs +++ b/sdk/emrserverless/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -519,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -538,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -575,7 +548,6 @@ mod test { /// Missing region #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -584,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to EMR Serverless +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -620,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/entityresolution/src/config.rs b/sdk/entityresolution/src/config.rs index 0bc8555bd76f..dc7e9f558bc7 100644 --- a/sdk/entityresolution/src/config.rs +++ b/sdk/entityresolution/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_entityresolution`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_entityresolution::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_entityresolution::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_entityresolution::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_entityresolution::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_entityresolution::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_entityresolution`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/entityresolution/src/config/endpoint.rs b/sdk/entityresolution/src/config/endpoint.rs index 886fe07ae2bb..db76a27311b7 100644 --- a/sdk/entityresolution/src/config/endpoint.rs +++ b/sdk/entityresolution/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS EntityResolution +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/eventbridge/src/config.rs b/sdk/eventbridge/src/config.rs index 41f228465d97..988367e74e95 100644 --- a/sdk/eventbridge/src/config.rs +++ b/sdk/eventbridge/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_eventbridge`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_eventbridge::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_eventbridge::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_eventbridge::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_eventbridge::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_eventbridge::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_eventbridge`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1152,7 +1134,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/eventbridge/src/config/endpoint.rs b/sdk/eventbridge/src/config/endpoint.rs index 64924d9e1577..cf8c27708e1f 100644 --- a/sdk/eventbridge/src/config/endpoint.rs +++ b/sdk/eventbridge/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1090,7 +1038,6 @@ mod test { /// Valid endpointId with fips disabled and dualstack disabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("abc123.456def".to_string()) .use_dual_stack(false) @@ -1125,7 +1072,6 @@ mod test { /// Valid EndpointId with dualstack disabled and fips enabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("abc123.456def".to_string()) .use_dual_stack(false) @@ -1145,7 +1091,6 @@ mod test { /// Valid EndpointId with dualstack enabled and fips enabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("abc123.456def".to_string()) .use_dual_stack(true) @@ -1165,7 +1110,6 @@ mod test { /// Invalid EndpointId #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("badactor.com?foo=bar".to_string()) .use_dual_stack(false) @@ -1182,7 +1126,6 @@ mod test { /// Invalid EndpointId (empty) #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("".to_string()) .use_dual_stack(false) @@ -1199,7 +1142,6 @@ mod test { /// Valid endpointId with fips disabled and dualstack true #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("abc123.456def".to_string()) .use_dual_stack(true) @@ -1234,7 +1176,6 @@ mod test { /// Valid endpointId with custom sdk endpoint #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("abc123.456def".to_string()) .use_dual_stack(true) @@ -1270,7 +1211,6 @@ mod test { /// Valid EndpointId with DualStack enabled and partition does not support DualStack #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint_id("abc123.456def".to_string()) .use_dual_stack(true) @@ -1285,6 +1225,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon EventBridge +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1327,27 +1331,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/evidently/src/config.rs b/sdk/evidently/src/config.rs index 43a3db482c78..bf90c31fc367 100644 --- a/sdk/evidently/src/config.rs +++ b/sdk/evidently/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_evidently`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_evidently::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_evidently::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_evidently::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_evidently::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_evidently::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_evidently`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/evidently/src/config/endpoint.rs b/sdk/evidently/src/config/endpoint.rs index 8d4cf22c29e5..062581f1a39a 100644 --- a/sdk/evidently/src/config/endpoint.rs +++ b/sdk/evidently/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -603,7 +575,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -622,7 +593,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -639,7 +609,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -659,7 +628,6 @@ mod test { /// Missing region #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -668,6 +636,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudWatch Evidently +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -704,27 +736,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/finspace/src/config.rs b/sdk/finspace/src/config.rs index 0d8a9bead909..09ae482c3ded 100644 --- a/sdk/finspace/src/config.rs +++ b/sdk/finspace/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_finspace`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_finspace::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_finspace::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_finspace::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_finspace::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_finspace::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_finspace`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/finspace/src/config/endpoint.rs b/sdk/finspace/src/config/endpoint.rs index fbd084761ed7..7a20d189f3e0 100644 --- a/sdk/finspace/src/config/endpoint.rs +++ b/sdk/finspace/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -519,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -538,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -575,7 +548,6 @@ mod test { /// Missing region #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -584,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to FinSpace User Environment Management service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -620,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/finspacedata/src/config.rs b/sdk/finspacedata/src/config.rs index 484210fcd780..aeb1edc9c601 100644 --- a/sdk/finspacedata/src/config.rs +++ b/sdk/finspacedata/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_finspacedata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_finspacedata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_finspacedata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_finspacedata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_finspacedata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_finspacedata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_finspacedata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/finspacedata/src/config/endpoint.rs b/sdk/finspacedata/src/config/endpoint.rs index 0dd55436fc26..a06d58aafd75 100644 --- a/sdk/finspacedata/src/config/endpoint.rs +++ b/sdk/finspacedata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -519,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -538,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -575,7 +548,6 @@ mod test { /// Missing region #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -584,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to FinSpace Public API +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -620,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/firehose/src/config.rs b/sdk/firehose/src/config.rs index 6b7c38c60bf6..5f29d6d6a166 100644 --- a/sdk/firehose/src/config.rs +++ b/sdk/firehose/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_firehose`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_firehose::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_firehose::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_firehose::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_firehose::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_firehose::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_firehose`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/firehose/src/config/endpoint.rs b/sdk/firehose/src/config/endpoint.rs index 67820ba7cef3..7281a323481e 100644 --- a/sdk/firehose/src/config/endpoint.rs +++ b/sdk/firehose/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Firehose +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/fis/src/config.rs b/sdk/fis/src/config.rs index 0caf47ac318f..6e868ae869be 100644 --- a/sdk/fis/src/config.rs +++ b/sdk/fis/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_fis`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_fis::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_fis::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_fis::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_fis::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_fis::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_fis`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/fis/src/config/endpoint.rs b/sdk/fis/src/config/endpoint.rs index 58d708c12c65..b4eda2b58f06 100644 --- a/sdk/fis/src/config/endpoint.rs +++ b/sdk/fis/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Fault Injection Simulator +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/fms/src/config.rs b/sdk/fms/src/config.rs index d8c9a6b18e1c..ed846fc3070a 100644 --- a/sdk/fms/src/config.rs +++ b/sdk/fms/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_fms`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_fms::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_fms::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_fms::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_fms::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_fms::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_fms`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/fms/src/config/endpoint.rs b/sdk/fms/src/config/endpoint.rs index 505b612eca81..424b820ac9ec 100644 --- a/sdk/fms/src/config/endpoint.rs +++ b/sdk/fms/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region af-south-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ap-south-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region ap-southeast-2 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region eu-central-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-south-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region eu-west-3 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region me-south-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region sa-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -849,7 +810,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -870,7 +830,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -912,7 +870,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -933,7 +890,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -954,7 +910,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -975,7 +930,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -996,7 +950,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1017,7 +970,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1038,7 +990,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1059,7 +1010,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -1080,7 +1030,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1101,7 +1050,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1122,7 +1070,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1141,7 +1088,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1162,7 +1108,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1178,7 +1123,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1199,7 +1143,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1218,7 +1161,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1239,7 +1181,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1255,7 +1196,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1276,7 +1216,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1296,7 +1235,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1315,7 +1253,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1332,7 +1269,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1352,7 +1288,6 @@ mod test { /// Missing region #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1361,6 +1296,70 @@ mod test { } } +/// Endpoint resolver trait specific to Firewall Management Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1397,27 +1396,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/forecast/src/config.rs b/sdk/forecast/src/config.rs index 8a6ddd509f9b..ffa0c8d2c33c 100644 --- a/sdk/forecast/src/config.rs +++ b/sdk/forecast/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_forecast`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_forecast::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_forecast::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_forecast::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_forecast::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_forecast::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_forecast`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/forecast/src/config/endpoint.rs b/sdk/forecast/src/config/endpoint.rs index cee1d7726f40..f5ecb51f3fed 100644 --- a/sdk/forecast/src/config/endpoint.rs +++ b/sdk/forecast/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -666,7 +635,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -685,7 +653,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -702,7 +669,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -722,7 +688,6 @@ mod test { /// Missing region #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -731,6 +696,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Forecast Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -767,27 +796,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/forecastquery/src/config.rs b/sdk/forecastquery/src/config.rs index 9733d2959fef..189a5c296c13 100644 --- a/sdk/forecastquery/src/config.rs +++ b/sdk/forecastquery/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_forecastquery`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_forecastquery::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_forecastquery::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_forecastquery::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_forecastquery::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_forecastquery::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_forecastquery`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/forecastquery/src/config/endpoint.rs b/sdk/forecastquery/src/config/endpoint.rs index 7abe9bab58f3..91cc61c1ad27 100644 --- a/sdk/forecastquery/src/config/endpoint.rs +++ b/sdk/forecastquery/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -666,7 +635,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -685,7 +653,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -702,7 +669,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -722,7 +688,6 @@ mod test { /// Missing region #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -731,6 +696,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Forecast Query Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -767,27 +796,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/frauddetector/src/config.rs b/sdk/frauddetector/src/config.rs index baa620cf7814..d43018805dbd 100644 --- a/sdk/frauddetector/src/config.rs +++ b/sdk/frauddetector/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_frauddetector`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_frauddetector::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_frauddetector::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_frauddetector::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_frauddetector::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_frauddetector::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_frauddetector`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/frauddetector/src/config/endpoint.rs b/sdk/frauddetector/src/config/endpoint.rs index 29cbb108843b..59d3f22defd6 100644 --- a/sdk/frauddetector/src/config/endpoint.rs +++ b/sdk/frauddetector/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Fraud Detector +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/fsx/src/config.rs b/sdk/fsx/src/config.rs index 981f8a07c91b..1de893f0fdfc 100644 --- a/sdk/fsx/src/config.rs +++ b/sdk/fsx/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_fsx`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_fsx::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_fsx::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_fsx::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_fsx::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_fsx::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_fsx`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/fsx/src/config/endpoint.rs b/sdk/fsx/src/config/endpoint.rs index 2aa9045dbcfc..b4d46b1c3b36 100644 --- a/sdk/fsx/src/config/endpoint.rs +++ b/sdk/fsx/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon FSx +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/gamelift/src/config.rs b/sdk/gamelift/src/config.rs index 225be8163545..0447d0a6c690 100644 --- a/sdk/gamelift/src/config.rs +++ b/sdk/gamelift/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_gamelift`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_gamelift::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_gamelift::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_gamelift::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_gamelift::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_gamelift::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_gamelift`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/gamelift/src/config/endpoint.rs b/sdk/gamelift/src/config/endpoint.rs index 33828dfe17aa..804d11b800d2 100644 --- a/sdk/gamelift/src/config/endpoint.rs +++ b/sdk/gamelift/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -876,7 +835,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -895,7 +853,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -912,7 +869,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -932,7 +888,6 @@ mod test { /// Missing region #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -941,6 +896,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon GameLift +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -977,27 +996,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/glacier/src/config.rs b/sdk/glacier/src/config.rs index dc4e32c50e62..2574930ee5d3 100644 --- a/sdk/glacier/src/config.rs +++ b/sdk/glacier/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_glacier`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_glacier::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_glacier::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_glacier::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_glacier::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_glacier::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_glacier`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1143,7 +1125,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/glacier/src/config/endpoint.rs b/sdk/glacier/src/config/endpoint.rs index 6264cd9444bb..86b8286db8ba 100644 --- a/sdk/glacier/src/config/endpoint.rs +++ b/sdk/glacier/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -931,7 +888,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -968,7 +923,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1008,7 +961,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1024,7 +976,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1044,7 +995,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1063,7 +1013,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1080,7 +1029,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1100,7 +1048,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1109,6 +1056,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Glacier +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1145,27 +1156,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/glacier/src/operation/upload_archive.rs b/sdk/glacier/src/operation/upload_archive.rs index 80f951cece4d..45a6074fb7f0 100644 --- a/sdk/glacier/src/operation/upload_archive.rs +++ b/sdk/glacier/src/operation/upload_archive.rs @@ -277,9 +277,7 @@ mod upload_archive_request_test { #[allow(unused_mut)] async fn glacier_version_header_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); @@ -306,9 +304,7 @@ mod upload_archive_request_test { #[allow(unused_mut)] async fn glacier_checksums_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); @@ -350,9 +346,7 @@ mod upload_archive_request_test { #[allow(unused_mut)] async fn glacier_account_id_empty_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); @@ -381,9 +375,7 @@ mod upload_archive_request_test { #[allow(unused_mut)] async fn glacier_account_id_unset_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/glacier/src/operation/upload_multipart_part.rs b/sdk/glacier/src/operation/upload_multipart_part.rs index 89d7d5b36110..41d1116397f6 100644 --- a/sdk/glacier/src/operation/upload_multipart_part.rs +++ b/sdk/glacier/src/operation/upload_multipart_part.rs @@ -289,9 +289,7 @@ mod upload_multipart_part_request_test { #[allow(unused_mut)] async fn glacier_multipart_checksums_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/globalaccelerator/src/config.rs b/sdk/globalaccelerator/src/config.rs index 2e53ca45a263..3e46992710c8 100644 --- a/sdk/globalaccelerator/src/config.rs +++ b/sdk/globalaccelerator/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_globalaccelerator`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_globalaccelerator::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_globalaccelerator::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_globalaccelerator::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_globalaccelerator::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_globalaccelerator::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_globalaccelerator`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/globalaccelerator/src/config/endpoint.rs b/sdk/globalaccelerator/src/config/endpoint.rs index 2e4d7c92acfd..ccc92e7bc147 100644 --- a/sdk/globalaccelerator/src/config/endpoint.rs +++ b/sdk/globalaccelerator/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Global Accelerator +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/glue/src/config.rs b/sdk/glue/src/config.rs index f5ebfa5639a6..77e5fa52d9cd 100644 --- a/sdk/glue/src/config.rs +++ b/sdk/glue/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_glue`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_glue::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_glue::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_glue::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_glue::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_glue::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_glue`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/glue/src/config/endpoint.rs b/sdk/glue/src/config/endpoint.rs index 893fe0048d96..a4a36b048cdb 100644 --- a/sdk/glue/src/config/endpoint.rs +++ b/sdk/glue/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Glue +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/grafana/src/config.rs b/sdk/grafana/src/config.rs index 6ecb119fb1bc..994f56679a2e 100644 --- a/sdk/grafana/src/config.rs +++ b/sdk/grafana/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_grafana`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_grafana::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_grafana::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_grafana::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_grafana::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_grafana::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_grafana`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/grafana/src/config/endpoint.rs b/sdk/grafana/src/config/endpoint.rs index a63cd0d769f2..92daaf27574f 100644 --- a/sdk/grafana/src/config/endpoint.rs +++ b/sdk/grafana/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -624,7 +595,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -643,7 +613,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -660,7 +629,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -680,7 +648,6 @@ mod test { /// Missing region #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -689,6 +656,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Managed Grafana +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -725,27 +756,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/greengrass/src/config.rs b/sdk/greengrass/src/config.rs index 6ae6e23203f4..5b7da81301b6 100644 --- a/sdk/greengrass/src/config.rs +++ b/sdk/greengrass/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_greengrass`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_greengrass::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_greengrass::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_greengrass::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_greengrass::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_greengrass::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_greengrass`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/greengrass/src/config/endpoint.rs b/sdk/greengrass/src/config/endpoint.rs index 5043a0e1a62b..5910f4d7e57a 100644 --- a/sdk/greengrass/src/config/endpoint.rs +++ b/sdk/greengrass/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region dataplane-us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("dataplane-us-gov-east-1".to_string()) .use_fips(false) @@ -439,7 +420,6 @@ mod test { /// For region dataplane-us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("dataplane-us-gov-west-1".to_string()) .use_fips(false) @@ -470,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -491,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -512,7 +490,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -533,7 +510,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -554,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -575,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -596,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -615,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -636,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -652,7 +623,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -673,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -692,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -713,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -729,7 +696,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -750,7 +716,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -770,7 +735,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -789,7 +753,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -806,7 +769,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -826,7 +788,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -835,6 +796,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Greengrass +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -871,27 +896,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/greengrassv2/src/config.rs b/sdk/greengrassv2/src/config.rs index 5f339a130a40..86e60605d22a 100644 --- a/sdk/greengrassv2/src/config.rs +++ b/sdk/greengrassv2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_greengrassv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_greengrassv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_greengrassv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_greengrassv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_greengrassv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_greengrassv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_greengrassv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/greengrassv2/src/config/endpoint.rs b/sdk/greengrassv2/src/config/endpoint.rs index 5043a0e1a62b..1fd7f4a7a9cc 100644 --- a/sdk/greengrassv2/src/config/endpoint.rs +++ b/sdk/greengrassv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region dataplane-us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("dataplane-us-gov-east-1".to_string()) .use_fips(false) @@ -439,7 +420,6 @@ mod test { /// For region dataplane-us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("dataplane-us-gov-west-1".to_string()) .use_fips(false) @@ -470,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -491,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -512,7 +490,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -533,7 +510,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -554,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -575,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -596,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -615,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -636,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -652,7 +623,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -673,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -692,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -713,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -729,7 +696,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -750,7 +716,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -770,7 +735,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -789,7 +753,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -806,7 +769,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -826,7 +788,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -835,6 +796,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Greengrass V2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -871,27 +896,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/groundstation/src/config.rs b/sdk/groundstation/src/config.rs index e96ecd0f8c2a..8f5957f54dce 100644 --- a/sdk/groundstation/src/config.rs +++ b/sdk/groundstation/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_groundstation`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_groundstation::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_groundstation::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_groundstation::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_groundstation::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_groundstation::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_groundstation`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/groundstation/src/config/endpoint.rs b/sdk/groundstation/src/config/endpoint.rs index f420796f6ed5..1bc03288d164 100644 --- a/sdk/groundstation/src/config/endpoint.rs +++ b/sdk/groundstation/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -687,7 +655,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -706,7 +673,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +689,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -743,7 +708,6 @@ mod test { /// Missing region #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -752,6 +716,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Ground Station +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -788,27 +816,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/guardduty/src/config.rs b/sdk/guardduty/src/config.rs index 34bd2e20c140..d753255edd60 100644 --- a/sdk/guardduty/src/config.rs +++ b/sdk/guardduty/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_guardduty`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_guardduty::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_guardduty::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_guardduty::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_guardduty::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_guardduty::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_guardduty`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/guardduty/src/config/endpoint.rs b/sdk/guardduty/src/config/endpoint.rs index 65a0c52ad640..d3b00a2a0441 100644 --- a/sdk/guardduty/src/config/endpoint.rs +++ b/sdk/guardduty/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon GuardDuty +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/health/src/config.rs b/sdk/health/src/config.rs index 300b3b90b24d..bf03e4898c92 100644 --- a/sdk/health/src/config.rs +++ b/sdk/health/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_health`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_health::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_health::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_health::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_health::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_health::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_health`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/health/src/config/endpoint.rs b/sdk/health/src/config/endpoint.rs index 318494dd7cce..90612bdaf3ae 100644 --- a/sdk/health/src/config/endpoint.rs +++ b/sdk/health/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -124,7 +120,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -155,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -176,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -197,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -218,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -239,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -260,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -281,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -302,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -323,7 +310,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -344,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -363,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -384,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -400,7 +383,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -421,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -440,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -461,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -477,7 +456,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -497,7 +475,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -516,7 +493,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -533,7 +509,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -553,7 +528,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -562,6 +536,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Health APIs and Notifications +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -598,27 +636,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/healthlake/src/config.rs b/sdk/healthlake/src/config.rs index 551ba074d92c..e99e23e045b1 100644 --- a/sdk/healthlake/src/config.rs +++ b/sdk/healthlake/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_healthlake`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_healthlake::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_healthlake::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_healthlake::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_healthlake::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_healthlake::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_healthlake`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/healthlake/src/config/endpoint.rs b/sdk/healthlake/src/config/endpoint.rs index f2392dd52d10..1d10fe1fdb97 100644 --- a/sdk/healthlake/src/config/endpoint.rs +++ b/sdk/healthlake/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon HealthLake +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/honeycode/src/config.rs b/sdk/honeycode/src/config.rs index 765192ffe3f9..7770faad53c4 100644 --- a/sdk/honeycode/src/config.rs +++ b/sdk/honeycode/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_honeycode`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_honeycode::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_honeycode::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_honeycode::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_honeycode::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_honeycode::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_honeycode`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/honeycode/src/config/endpoint.rs b/sdk/honeycode/src/config/endpoint.rs index 8259286890e7..f85378e35fb2 100644 --- a/sdk/honeycode/src/config/endpoint.rs +++ b/sdk/honeycode/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Honeycode +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iam/src/config.rs b/sdk/iam/src/config.rs index 7066567ded1b..ebc31360c717 100644 --- a/sdk/iam/src/config.rs +++ b/sdk/iam/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iam`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iam::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iam::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iam::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iam::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iam::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iam`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iam/src/config/endpoint.rs b/sdk/iam/src/config/endpoint.rs index 0edf608dde77..bac61cb615f4 100644 --- a/sdk/iam/src/config/endpoint.rs +++ b/sdk/iam/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region aws-global with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -71,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -92,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -123,7 +120,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -144,7 +140,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -175,7 +170,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -206,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -227,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -248,7 +240,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -269,7 +260,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -300,7 +290,6 @@ mod test { /// For region aws-us-gov-global with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(false) @@ -331,7 +320,6 @@ mod test { /// For region aws-us-gov-global with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(true) @@ -362,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -383,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -414,7 +400,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -435,7 +420,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -466,7 +450,6 @@ mod test { /// For region aws-iso-global with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-iso-global".to_string()) .use_fips(false) @@ -497,7 +480,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -516,7 +498,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -537,7 +518,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -553,7 +533,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -584,7 +563,6 @@ mod test { /// For region aws-iso-b-global with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-iso-b-global".to_string()) .use_fips(false) @@ -615,7 +593,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -634,7 +611,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -655,7 +631,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -671,7 +646,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -702,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -722,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -741,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -758,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -778,7 +748,6 @@ mod test { /// Missing region #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -787,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Identity and Access Management +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -823,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/identitystore/src/config.rs b/sdk/identitystore/src/config.rs index 2aec6787b488..5911dab30e00 100644 --- a/sdk/identitystore/src/config.rs +++ b/sdk/identitystore/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_identitystore`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_identitystore::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_identitystore::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_identitystore::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_identitystore::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_identitystore::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_identitystore`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/identitystore/src/config/endpoint.rs b/sdk/identitystore/src/config/endpoint.rs index 4cf95bc546d7..619886fe2420 100644 --- a/sdk/identitystore/src/config/endpoint.rs +++ b/sdk/identitystore/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -729,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -748,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -765,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -785,7 +748,6 @@ mod test { /// Missing region #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -794,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS SSO Identity Store +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -830,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/imagebuilder/src/config.rs b/sdk/imagebuilder/src/config.rs index 031705b0dc7a..77486285b72a 100644 --- a/sdk/imagebuilder/src/config.rs +++ b/sdk/imagebuilder/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_imagebuilder`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_imagebuilder::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_imagebuilder::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_imagebuilder::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_imagebuilder::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_imagebuilder::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_imagebuilder`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/imagebuilder/src/config/endpoint.rs b/sdk/imagebuilder/src/config/endpoint.rs index b508edbf27ef..65548590b4dd 100644 --- a/sdk/imagebuilder/src/config/endpoint.rs +++ b/sdk/imagebuilder/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to EC2 Image Builder +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/inspector/src/config.rs b/sdk/inspector/src/config.rs index c9b2525525fc..1b8b898eb908 100644 --- a/sdk/inspector/src/config.rs +++ b/sdk/inspector/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_inspector`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_inspector::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_inspector::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_inspector::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_inspector::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_inspector::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_inspector`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/inspector/src/config/endpoint.rs b/sdk/inspector/src/config/endpoint.rs index 709e9003717e..944671acd077 100644 --- a/sdk/inspector/src/config/endpoint.rs +++ b/sdk/inspector/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -751,7 +716,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -771,7 +735,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -790,7 +753,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +769,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -827,7 +788,6 @@ mod test { /// Missing region #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -836,6 +796,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Inspector +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -872,27 +896,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/inspector2/src/config.rs b/sdk/inspector2/src/config.rs index d90bf2bd7b7d..60153230b1cb 100644 --- a/sdk/inspector2/src/config.rs +++ b/sdk/inspector2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_inspector2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_inspector2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_inspector2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_inspector2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_inspector2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_inspector2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_inspector2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/inspector2/src/config/endpoint.rs b/sdk/inspector2/src/config/endpoint.rs index a9eb60376a0e..e792e3182501 100644 --- a/sdk/inspector2/src/config/endpoint.rs +++ b/sdk/inspector2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -658,7 +628,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -695,7 +663,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -735,7 +701,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -772,7 +736,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -813,7 +775,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -832,7 +793,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -849,7 +809,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -869,7 +828,6 @@ mod test { /// Missing region #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -878,6 +836,70 @@ mod test { } } +/// Endpoint resolver trait specific to Inspector2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -914,27 +936,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/internetmonitor/src/config.rs b/sdk/internetmonitor/src/config.rs index ac91107f2351..f50eb57711a2 100644 --- a/sdk/internetmonitor/src/config.rs +++ b/sdk/internetmonitor/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_internetmonitor`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_internetmonitor::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_internetmonitor::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_internetmonitor::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_internetmonitor::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_internetmonitor::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_internetmonitor`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/internetmonitor/src/config/endpoint.rs b/sdk/internetmonitor/src/config/endpoint.rs index d9b8691dc60e..d2a0f16a3c8b 100644 --- a/sdk/internetmonitor/src/config/endpoint.rs +++ b/sdk/internetmonitor/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon CloudWatch Internet Monitor +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iot/src/config.rs b/sdk/iot/src/config.rs index e21874f1ce1f..df645614312a 100644 --- a/sdk/iot/src/config.rs +++ b/sdk/iot/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iot`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iot::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iot::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iot::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iot::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iot::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iot`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iot/src/config/endpoint.rs b/sdk/iot/src/config/endpoint.rs index ef6be1a858f1..5294e136a13c 100644 --- a/sdk/iot/src/config/endpoint.rs +++ b/sdk/iot/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iot1clickdevices/src/config.rs b/sdk/iot1clickdevices/src/config.rs index d300504c1b93..0552de73e286 100644 --- a/sdk/iot1clickdevices/src/config.rs +++ b/sdk/iot1clickdevices/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iot1clickdevices`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iot1clickdevices::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iot1clickdevices::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iot1clickdevices::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iot1clickdevices::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iot1clickdevices::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iot1clickdevices`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iot1clickdevices/src/config/endpoint.rs b/sdk/iot1clickdevices/src/config/endpoint.rs index c62dd0c9742d..1b544f3a8ed0 100644 --- a/sdk/iot1clickdevices/src/config/endpoint.rs +++ b/sdk/iot1clickdevices/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT 1-Click Devices Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iot1clickprojects/src/config.rs b/sdk/iot1clickprojects/src/config.rs index 5015700bd7fc..ccc3a6fd26d5 100644 --- a/sdk/iot1clickprojects/src/config.rs +++ b/sdk/iot1clickprojects/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iot1clickprojects`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iot1clickprojects::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iot1clickprojects::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iot1clickprojects::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iot1clickprojects::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iot1clickprojects::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iot1clickprojects`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iot1clickprojects/src/config/endpoint.rs b/sdk/iot1clickprojects/src/config/endpoint.rs index 1cc3292e99a1..ac3a28a2e2e7 100644 --- a/sdk/iot1clickprojects/src/config/endpoint.rs +++ b/sdk/iot1clickprojects/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT 1-Click Projects Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotanalytics/src/config.rs b/sdk/iotanalytics/src/config.rs index 559658275627..ca4b69ddb80b 100644 --- a/sdk/iotanalytics/src/config.rs +++ b/sdk/iotanalytics/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotanalytics`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotanalytics::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotanalytics::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotanalytics::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotanalytics::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotanalytics::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotanalytics`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotanalytics/src/config/endpoint.rs b/sdk/iotanalytics/src/config/endpoint.rs index a07369660ba5..6d3d64e8d5c2 100644 --- a/sdk/iotanalytics/src/config/endpoint.rs +++ b/sdk/iotanalytics/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -582,7 +555,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -601,7 +573,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -618,7 +589,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -638,7 +608,6 @@ mod test { /// Missing region #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -647,6 +616,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Analytics +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -683,27 +716,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotdataplane/src/config.rs b/sdk/iotdataplane/src/config.rs index 74cc57862417..f6afc9a5b564 100644 --- a/sdk/iotdataplane/src/config.rs +++ b/sdk/iotdataplane/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotdataplane`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotdataplane::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotdataplane::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotdataplane::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotdataplane::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotdataplane::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotdataplane`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotdataplane/src/config/endpoint.rs b/sdk/iotdataplane/src/config/endpoint.rs index 468e38854d18..180baa904d02 100644 --- a/sdk/iotdataplane/src/config/endpoint.rs +++ b/sdk/iotdataplane/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Data Plane +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotdeviceadvisor/src/config.rs b/sdk/iotdeviceadvisor/src/config.rs index a3ee1d7a6775..0dffdfd4b2dc 100644 --- a/sdk/iotdeviceadvisor/src/config.rs +++ b/sdk/iotdeviceadvisor/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotdeviceadvisor`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotdeviceadvisor::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotdeviceadvisor::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotdeviceadvisor::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotdeviceadvisor::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotdeviceadvisor::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotdeviceadvisor`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotdeviceadvisor/src/config/endpoint.rs b/sdk/iotdeviceadvisor/src/config/endpoint.rs index 17820e189f74..7cc305bd61f3 100644 --- a/sdk/iotdeviceadvisor/src/config/endpoint.rs +++ b/sdk/iotdeviceadvisor/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -498,7 +475,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -517,7 +493,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -534,7 +509,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -554,7 +528,6 @@ mod test { /// Missing region #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -563,6 +536,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Core Device Advisor +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -599,27 +636,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotevents/src/config.rs b/sdk/iotevents/src/config.rs index 4d23b14c1691..253eb1700123 100644 --- a/sdk/iotevents/src/config.rs +++ b/sdk/iotevents/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotevents`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotevents::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotevents::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotevents::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotevents::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotevents::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotevents`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotevents/src/config/endpoint.rs b/sdk/iotevents/src/config/endpoint.rs index ab4a44cfa52b..05e07906ba4b 100644 --- a/sdk/iotevents/src/config/endpoint.rs +++ b/sdk/iotevents/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -687,7 +655,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -706,7 +673,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +689,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -743,7 +708,6 @@ mod test { /// Missing region #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -752,6 +716,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Events +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -788,27 +816,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ioteventsdata/src/config.rs b/sdk/ioteventsdata/src/config.rs index 80982325fa64..471dfaccf73a 100644 --- a/sdk/ioteventsdata/src/config.rs +++ b/sdk/ioteventsdata/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ioteventsdata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ioteventsdata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ioteventsdata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ioteventsdata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ioteventsdata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ioteventsdata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ioteventsdata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ioteventsdata/src/config/endpoint.rs b/sdk/ioteventsdata/src/config/endpoint.rs index e9e0becf0b4d..2040a8e39432 100644 --- a/sdk/ioteventsdata/src/config/endpoint.rs +++ b/sdk/ioteventsdata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Events Data +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotfleethub/src/config.rs b/sdk/iotfleethub/src/config.rs index 67a8dae5157f..6e93369d7758 100644 --- a/sdk/iotfleethub/src/config.rs +++ b/sdk/iotfleethub/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotfleethub`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotfleethub::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotfleethub::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotfleethub::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotfleethub::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotfleethub::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotfleethub`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotfleethub/src/config/endpoint.rs b/sdk/iotfleethub/src/config/endpoint.rs index a7b9fa977cb7..4666a9605717 100644 --- a/sdk/iotfleethub/src/config/endpoint.rs +++ b/sdk/iotfleethub/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Fleet Hub +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotfleetwise/src/config.rs b/sdk/iotfleetwise/src/config.rs index 8332a4389bd8..b028f82aa57a 100644 --- a/sdk/iotfleetwise/src/config.rs +++ b/sdk/iotfleetwise/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotfleetwise`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotfleetwise::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotfleetwise::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotfleetwise::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotfleetwise::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotfleetwise::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotfleetwise`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotfleetwise/src/config/endpoint.rs b/sdk/iotfleetwise/src/config/endpoint.rs index 1ad6a0f00aef..0ce0dba2ac9b 100644 --- a/sdk/iotfleetwise/src/config/endpoint.rs +++ b/sdk/iotfleetwise/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT FleetWise +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotjobsdataplane/src/config.rs b/sdk/iotjobsdataplane/src/config.rs index d42c8bbcfb4f..93ba1b486b07 100644 --- a/sdk/iotjobsdataplane/src/config.rs +++ b/sdk/iotjobsdataplane/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotjobsdataplane`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotjobsdataplane::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotjobsdataplane::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotjobsdataplane::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotjobsdataplane::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotjobsdataplane::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotjobsdataplane`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotjobsdataplane/src/config/endpoint.rs b/sdk/iotjobsdataplane/src/config/endpoint.rs index 4fb631b20eb9..4db44628ed01 100644 --- a/sdk/iotjobsdataplane/src/config/endpoint.rs +++ b/sdk/iotjobsdataplane/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Jobs Data Plane +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotroborunner/src/config.rs b/sdk/iotroborunner/src/config.rs index 14de2fb6b575..73196b8fcfd5 100644 --- a/sdk/iotroborunner/src/config.rs +++ b/sdk/iotroborunner/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotroborunner`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotroborunner::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotroborunner::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotroborunner::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotroborunner::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotroborunner::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotroborunner`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotroborunner/src/config/endpoint.rs b/sdk/iotroborunner/src/config/endpoint.rs index 290b28ce8207..14ed94137673 100644 --- a/sdk/iotroborunner/src/config/endpoint.rs +++ b/sdk/iotroborunner/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT RoboRunner +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotsecuretunneling/src/config.rs b/sdk/iotsecuretunneling/src/config.rs index d441546b7b9a..e7dfc2399440 100644 --- a/sdk/iotsecuretunneling/src/config.rs +++ b/sdk/iotsecuretunneling/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotsecuretunneling`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotsecuretunneling::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotsecuretunneling::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotsecuretunneling::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotsecuretunneling::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotsecuretunneling::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotsecuretunneling`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotsecuretunneling/src/config/endpoint.rs b/sdk/iotsecuretunneling/src/config/endpoint.rs index 7e89c8f7012f..b7b43252c147 100644 --- a/sdk/iotsecuretunneling/src/config/endpoint.rs +++ b/sdk/iotsecuretunneling/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Secure Tunneling +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotsitewise/src/config.rs b/sdk/iotsitewise/src/config.rs index f222619dda4b..71e0269a2d21 100644 --- a/sdk/iotsitewise/src/config.rs +++ b/sdk/iotsitewise/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotsitewise`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotsitewise::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotsitewise::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotsitewise::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotsitewise::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotsitewise::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotsitewise`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotsitewise/src/config/endpoint.rs b/sdk/iotsitewise/src/config/endpoint.rs index f8f0766c47f5..78b5e16d6c9f 100644 --- a/sdk/iotsitewise/src/config/endpoint.rs +++ b/sdk/iotsitewise/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT SiteWise +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotthingsgraph/src/config.rs b/sdk/iotthingsgraph/src/config.rs index 2df1a9d1367b..6d524c4571b4 100644 --- a/sdk/iotthingsgraph/src/config.rs +++ b/sdk/iotthingsgraph/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotthingsgraph`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotthingsgraph::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotthingsgraph::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotthingsgraph::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotthingsgraph::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotthingsgraph::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotthingsgraph`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotthingsgraph/src/config/endpoint.rs b/sdk/iotthingsgraph/src/config/endpoint.rs index f27c4ba1424e..da9c8c99397c 100644 --- a/sdk/iotthingsgraph/src/config/endpoint.rs +++ b/sdk/iotthingsgraph/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Things Graph +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iottwinmaker/src/config.rs b/sdk/iottwinmaker/src/config.rs index 112e7b98c5aa..672e84864bca 100644 --- a/sdk/iottwinmaker/src/config.rs +++ b/sdk/iottwinmaker/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iottwinmaker`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iottwinmaker::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iottwinmaker::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iottwinmaker::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iottwinmaker::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iottwinmaker::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iottwinmaker`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iottwinmaker/src/config/endpoint.rs b/sdk/iottwinmaker/src/config/endpoint.rs index 2acb8915f330..097713a63e8e 100644 --- a/sdk/iottwinmaker/src/config/endpoint.rs +++ b/sdk/iottwinmaker/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT TwinMaker +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/iotwireless/src/config.rs b/sdk/iotwireless/src/config.rs index 5b455ac1f433..d2334dcec8aa 100644 --- a/sdk/iotwireless/src/config.rs +++ b/sdk/iotwireless/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotwireless`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_iotwireless::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_iotwireless::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_iotwireless::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_iotwireless::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_iotwireless::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_iotwireless`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/iotwireless/src/config/endpoint.rs b/sdk/iotwireless/src/config/endpoint.rs index 4098750742e5..4888706773e6 100644 --- a/sdk/iotwireless/src/config/endpoint.rs +++ b/sdk/iotwireless/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -519,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -538,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -575,7 +548,6 @@ mod test { /// Missing region #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -584,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS IoT Wireless +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -620,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ivs/src/config.rs b/sdk/ivs/src/config.rs index 3cacea0e9ff3..d1864d1676f4 100644 --- a/sdk/ivs/src/config.rs +++ b/sdk/ivs/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ivs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ivs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ivs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ivs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ivs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ivs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ivs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ivs/src/config/endpoint.rs b/sdk/ivs/src/config/endpoint.rs index c1e6625c4223..057e9c3e3219 100644 --- a/sdk/ivs/src/config/endpoint.rs +++ b/sdk/ivs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Interactive Video Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ivschat/src/config.rs b/sdk/ivschat/src/config.rs index 3a6cfec77480..af92a0fc2752 100644 --- a/sdk/ivschat/src/config.rs +++ b/sdk/ivschat/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ivschat`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ivschat::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ivschat::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ivschat::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ivschat::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ivschat::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ivschat`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ivschat/src/config/endpoint.rs b/sdk/ivschat/src/config/endpoint.rs index e25f425a722f..9e1879e9d163 100644 --- a/sdk/ivschat/src/config/endpoint.rs +++ b/sdk/ivschat/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Interactive Video Service Chat +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ivsrealtime/src/config.rs b/sdk/ivsrealtime/src/config.rs index 6b48a2965ab1..ddaab13cd781 100644 --- a/sdk/ivsrealtime/src/config.rs +++ b/sdk/ivsrealtime/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ivsrealtime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ivsrealtime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ivsrealtime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ivsrealtime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ivsrealtime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ivsrealtime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ivsrealtime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ivsrealtime/src/config/endpoint.rs b/sdk/ivsrealtime/src/config/endpoint.rs index dce0f0625ab6..af0bc20b933d 100644 --- a/sdk/ivsrealtime/src/config/endpoint.rs +++ b/sdk/ivsrealtime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Interactive Video Service RealTime +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kafka/src/config.rs b/sdk/kafka/src/config.rs index fa26df9cf9f3..4dc4f59446ae 100644 --- a/sdk/kafka/src/config.rs +++ b/sdk/kafka/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kafka`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kafka::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kafka::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kafka::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kafka::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kafka::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kafka`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kafka/src/config/endpoint.rs b/sdk/kafka/src/config/endpoint.rs index b41d7449661a..1cd7e60b6914 100644 --- a/sdk/kafka/src/config/endpoint.rs +++ b/sdk/kafka/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -918,7 +875,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -937,7 +893,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +909,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -974,7 +928,6 @@ mod test { /// Missing region #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -983,6 +936,70 @@ mod test { } } +/// Endpoint resolver trait specific to Managed Streaming for Kafka +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1019,27 +1036,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kafkaconnect/src/config.rs b/sdk/kafkaconnect/src/config.rs index e1df76a1927a..9756c130252a 100644 --- a/sdk/kafkaconnect/src/config.rs +++ b/sdk/kafkaconnect/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kafkaconnect`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kafkaconnect::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kafkaconnect::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kafkaconnect::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kafkaconnect::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kafkaconnect::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kafkaconnect`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kafkaconnect/src/config/endpoint.rs b/sdk/kafkaconnect/src/config/endpoint.rs index a841835ef607..c4a9d083af6b 100644 --- a/sdk/kafkaconnect/src/config/endpoint.rs +++ b/sdk/kafkaconnect/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Managed Streaming for Kafka Connect +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kendra/src/config.rs b/sdk/kendra/src/config.rs index c288cd8f72a6..8d81dca019ca 100644 --- a/sdk/kendra/src/config.rs +++ b/sdk/kendra/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kendra`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kendra::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kendra::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kendra::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kendra::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kendra::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kendra`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kendra/src/config/endpoint.rs b/sdk/kendra/src/config/endpoint.rs index 859a915584fb..72fad1ded814 100644 --- a/sdk/kendra/src/config/endpoint.rs +++ b/sdk/kendra/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWSKendraFrontendService +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kendraranking/src/config.rs b/sdk/kendraranking/src/config.rs index 4ccda4feddff..d8240eab8866 100644 --- a/sdk/kendraranking/src/config.rs +++ b/sdk/kendraranking/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kendraranking`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kendraranking::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kendraranking::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kendraranking::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kendraranking::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kendraranking::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kendraranking`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -957,11 +940,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1152,7 +1134,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kendraranking/src/config/endpoint.rs b/sdk/kendraranking/src/config/endpoint.rs index c56d82cf4588..64785af43ed1 100644 --- a/sdk/kendraranking/src/config/endpoint.rs +++ b/sdk/kendraranking/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -29,7 +29,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -49,7 +48,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -69,7 +67,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -89,7 +86,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -109,7 +105,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -129,7 +124,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -148,7 +142,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .endpoint("https://example.com".to_string()) @@ -166,7 +159,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -182,7 +174,6 @@ mod test { /// Missing region #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -191,6 +182,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kendra Intelligent Ranking +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -221,27 +276,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/keyspaces/src/config.rs b/sdk/keyspaces/src/config.rs index b0fdf1183511..a806a63ce80e 100644 --- a/sdk/keyspaces/src/config.rs +++ b/sdk/keyspaces/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_keyspaces`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_keyspaces::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_keyspaces::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_keyspaces::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_keyspaces::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_keyspaces::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_keyspaces`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/keyspaces/src/config/endpoint.rs b/sdk/keyspaces/src/config/endpoint.rs index a75407bfa443..196cf9775a95 100644 --- a/sdk/keyspaces/src/config/endpoint.rs +++ b/sdk/keyspaces/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Keyspaces +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesis/src/config.rs b/sdk/kinesis/src/config.rs index 5d30a69faaef..ff83fe408e94 100644 --- a/sdk/kinesis/src/config.rs +++ b/sdk/kinesis/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesis`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesis::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesis::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesis::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesis::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesis::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesis`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesis/src/config/endpoint.rs b/sdk/kinesis/src/config/endpoint.rs index c579e344ad0f..1a2b56968b80 100644 --- a/sdk/kinesis/src/config/endpoint.rs +++ b/sdk/kinesis/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1090,7 +1038,6 @@ mod test { /// Invalid ARN: Failed to parse ARN. #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1107,7 +1054,6 @@ mod test { /// Invalid ARN: partition missing from ARN. #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1124,7 +1070,6 @@ mod test { /// Invalid ARN: partitions mismatch. #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1145,7 +1090,6 @@ mod test { /// Invalid ARN: Not Kinesis #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1163,7 +1107,6 @@ mod test { /// Invalid ARN: Region is missing in ARN #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1180,7 +1123,6 @@ mod test { /// Invalid ARN: Region is empty string in ARN #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1197,7 +1139,6 @@ mod test { /// Invalid ARN: Invalid account id #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1215,7 +1156,6 @@ mod test { /// Invalid ARN: Invalid account id #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1233,7 +1173,6 @@ mod test { /// Invalid ARN: Kinesis ARNs only support stream arn types #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1250,7 +1189,6 @@ mod test { /// Dual Stack not supported region. #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(true) @@ -1273,7 +1211,6 @@ mod test { /// OperationType not set #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1294,7 +1231,6 @@ mod test { /// Custom Endpoint is specified #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1316,7 +1252,6 @@ mod test { /// Account endpoint targeting control operation type #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1339,7 +1274,6 @@ mod test { /// Account endpoint targeting data operation type #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1362,7 +1296,6 @@ mod test { /// Account endpoint with fips targeting data operation type #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1385,7 +1318,6 @@ mod test { /// Account endpoint with fips targeting control operation type #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1408,7 +1340,6 @@ mod test { /// Account endpoint with Dual Stack and FIPS enabled #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1431,7 +1362,6 @@ mod test { /// Account endpoint with Dual Stack enabled #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -1454,7 +1384,6 @@ mod test { /// Account endpoint with FIPS and DualStack disabled #[test] fn test_72() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -1477,7 +1406,6 @@ mod test { /// RegionMismatch: client region should be used for endpoint region #[test] fn test_73() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1500,7 +1428,6 @@ mod test { /// Account endpoint with FIPS enabled #[test] fn test_74() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -1523,7 +1450,6 @@ mod test { /// Account endpoint with FIPS and DualStack enabled for cn regions. #[test] fn test_75() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -1546,7 +1472,6 @@ mod test { /// Account endpoint targeting control operation type in ADC regions #[test] fn test_76() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1569,7 +1494,6 @@ mod test { /// Account endpoint targeting control operation type in ADC regions #[test] fn test_77() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -1592,7 +1516,6 @@ mod test { /// Account endpoint targeting data operation type in ADC regions #[test] fn test_78() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1615,7 +1538,6 @@ mod test { /// Account endpoint with fips targeting control operation type in ADC regions #[test] fn test_79() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1638,7 +1560,6 @@ mod test { /// Account endpoint with fips targeting data operation type in ADC regions #[test] fn test_80() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1661,7 +1582,6 @@ mod test { /// Invalid ConsumerARN: Failed to parse ARN. #[test] fn test_81() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1678,7 +1598,6 @@ mod test { /// Invalid ConsumerARN: partition missing from ARN. #[test] fn test_82() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1695,7 +1614,6 @@ mod test { /// Invalid ARN: partitions mismatch. #[test] fn test_83() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1716,7 +1634,6 @@ mod test { /// Invalid ARN: Not Kinesis #[test] fn test_84() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1734,7 +1651,6 @@ mod test { /// Invalid ARN: Region is missing in ARN #[test] fn test_85() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1751,7 +1667,6 @@ mod test { /// Invalid ARN: Region is empty string in ARN #[test] fn test_86() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1768,7 +1683,6 @@ mod test { /// Invalid ARN: Invalid account id #[test] fn test_87() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1786,7 +1700,6 @@ mod test { /// Invalid ARN: Invalid account id #[test] fn test_88() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1804,7 +1717,6 @@ mod test { /// Invalid ARN: Kinesis ARNs only support stream arn/consumer arn types #[test] fn test_89() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1821,7 +1733,6 @@ mod test { /// Dual Stack not supported region. #[test] fn test_90() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(true) @@ -1844,7 +1755,6 @@ mod test { /// OperationType not set #[test] fn test_91() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1865,7 +1775,6 @@ mod test { /// Custom Endpoint is specified #[test] fn test_92() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1887,7 +1796,6 @@ mod test { /// Account endpoint targeting control operation type #[test] fn test_93() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1910,7 +1818,6 @@ mod test { /// Account endpoint targeting data operation type #[test] fn test_94() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1933,7 +1840,6 @@ mod test { /// Account endpoint with fips targeting data operation type #[test] fn test_95() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1956,7 +1862,6 @@ mod test { /// Account endpoint with fips targeting control operation type #[test] fn test_96() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1979,7 +1884,6 @@ mod test { /// Account endpoint with Dual Stack and FIPS enabled #[test] fn test_97() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -2002,7 +1906,6 @@ mod test { /// Account endpoint with Dual Stack enabled #[test] fn test_98() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -2025,7 +1928,6 @@ mod test { /// Account endpoint with FIPS and DualStack disabled #[test] fn test_99() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -2048,7 +1950,6 @@ mod test { /// RegionMismatch: client region should be used for endpoint region #[test] fn test_100() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -2071,7 +1972,6 @@ mod test { /// Account endpoint with FIPS enabled #[test] fn test_101() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -2094,7 +1994,6 @@ mod test { /// Account endpoint with FIPS and DualStack enabled for cn regions. #[test] fn test_102() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -2117,7 +2016,6 @@ mod test { /// Account endpoint targeting control operation type in ADC regions #[test] fn test_103() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -2140,7 +2038,6 @@ mod test { /// Account endpoint targeting control operation type in ADC regions #[test] fn test_104() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -2163,7 +2060,6 @@ mod test { /// Account endpoint targeting data operation type in ADC regions #[test] fn test_105() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -2186,7 +2082,6 @@ mod test { /// Account endpoint with fips targeting control operation type in ADC regions #[test] fn test_106() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -2209,7 +2104,6 @@ mod test { /// Account endpoint with fips targeting data operation type in ADC regions #[test] fn test_107() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -2232,7 +2126,6 @@ mod test { /// ConsumerARN targeting US-EAST-1 #[test] fn test_108() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -2255,7 +2148,6 @@ mod test { /// Both StreamARN and ConsumerARN specified. StreamARN should take precedence #[test] fn test_109() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -2277,6 +2169,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -2331,27 +2287,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesisanalytics/src/config.rs b/sdk/kinesisanalytics/src/config.rs index 34202652f349..30c596344717 100644 --- a/sdk/kinesisanalytics/src/config.rs +++ b/sdk/kinesisanalytics/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisanalytics`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesisanalytics::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesisanalytics::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesisanalytics::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesisanalytics::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesisanalytics::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisanalytics`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesisanalytics/src/config/endpoint.rs b/sdk/kinesisanalytics/src/config/endpoint.rs index 0b67826f140a..3260e5bde901 100644 --- a/sdk/kinesisanalytics/src/config/endpoint.rs +++ b/sdk/kinesisanalytics/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Analytics +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesisanalyticsv2/src/config.rs b/sdk/kinesisanalyticsv2/src/config.rs index c45765bd4fa3..f48923683f7f 100644 --- a/sdk/kinesisanalyticsv2/src/config.rs +++ b/sdk/kinesisanalyticsv2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisanalyticsv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesisanalyticsv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesisanalyticsv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesisanalyticsv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesisanalyticsv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesisanalyticsv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisanalyticsv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesisanalyticsv2/src/config/endpoint.rs b/sdk/kinesisanalyticsv2/src/config/endpoint.rs index 0b67826f140a..3260e5bde901 100644 --- a/sdk/kinesisanalyticsv2/src/config/endpoint.rs +++ b/sdk/kinesisanalyticsv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Analytics +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesisvideo/src/config.rs b/sdk/kinesisvideo/src/config.rs index a80428c90cd7..57301a59d4c4 100644 --- a/sdk/kinesisvideo/src/config.rs +++ b/sdk/kinesisvideo/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideo`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesisvideo::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesisvideo::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesisvideo::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesisvideo::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesisvideo::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideo`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesisvideo/src/config/endpoint.rs b/sdk/kinesisvideo/src/config/endpoint.rs index cf1f71ace320..4d0e4ff90b02 100644 --- a/sdk/kinesisvideo/src/config/endpoint.rs +++ b/sdk/kinesisvideo/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Video Streams +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesisvideoarchivedmedia/src/config.rs b/sdk/kinesisvideoarchivedmedia/src/config.rs index fea7703ad9e7..6f40a0a5385c 100644 --- a/sdk/kinesisvideoarchivedmedia/src/config.rs +++ b/sdk/kinesisvideoarchivedmedia/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideoarchivedmedia`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesisvideoarchivedmedia::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesisvideoarchivedmedia::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesisvideoarchivedmedia::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesisvideoarchivedmedia::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesisvideoarchivedmedia::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideoarchivedmedia`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesisvideoarchivedmedia/src/config/endpoint.rs b/sdk/kinesisvideoarchivedmedia/src/config/endpoint.rs index cf1f71ace320..37c4e49759da 100644 --- a/sdk/kinesisvideoarchivedmedia/src/config/endpoint.rs +++ b/sdk/kinesisvideoarchivedmedia/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Video Streams Archived Media +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesisvideomedia/src/config.rs b/sdk/kinesisvideomedia/src/config.rs index b9d5975c1ac3..5c4dbaca3f3b 100644 --- a/sdk/kinesisvideomedia/src/config.rs +++ b/sdk/kinesisvideomedia/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideomedia`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesisvideomedia::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesisvideomedia::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesisvideomedia::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesisvideomedia::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesisvideomedia::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideomedia`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesisvideomedia/src/config/endpoint.rs b/sdk/kinesisvideomedia/src/config/endpoint.rs index cf1f71ace320..a3a006c788eb 100644 --- a/sdk/kinesisvideomedia/src/config/endpoint.rs +++ b/sdk/kinesisvideomedia/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Video Streams Media +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesisvideosignaling/src/config.rs b/sdk/kinesisvideosignaling/src/config.rs index 5bd42c6912b7..6f35d72d2777 100644 --- a/sdk/kinesisvideosignaling/src/config.rs +++ b/sdk/kinesisvideosignaling/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideosignaling`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesisvideosignaling::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesisvideosignaling::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesisvideosignaling::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesisvideosignaling::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesisvideosignaling::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideosignaling`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesisvideosignaling/src/config/endpoint.rs b/sdk/kinesisvideosignaling/src/config/endpoint.rs index cf1f71ace320..c8e38269863a 100644 --- a/sdk/kinesisvideosignaling/src/config/endpoint.rs +++ b/sdk/kinesisvideosignaling/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Video Signaling Channels +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kinesisvideowebrtcstorage/src/config.rs b/sdk/kinesisvideowebrtcstorage/src/config.rs index f7b98f5d706a..cef878ab09ab 100644 --- a/sdk/kinesisvideowebrtcstorage/src/config.rs +++ b/sdk/kinesisvideowebrtcstorage/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideowebrtcstorage`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kinesisvideowebrtcstorage::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kinesisvideowebrtcstorage::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kinesisvideowebrtcstorage::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kinesisvideowebrtcstorage::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kinesisvideowebrtcstorage::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kinesisvideowebrtcstorage`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kinesisvideowebrtcstorage/src/config/endpoint.rs b/sdk/kinesisvideowebrtcstorage/src/config/endpoint.rs index 35eb774e243f..bbb0a2af27f2 100644 --- a/sdk/kinesisvideowebrtcstorage/src/config/endpoint.rs +++ b/sdk/kinesisvideowebrtcstorage/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Kinesis Video WebRTC Storage +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/kms/src/config.rs b/sdk/kms/src/config.rs index d3f30faec3b9..f8474205f3d1 100644 --- a/sdk/kms/src/config.rs +++ b/sdk/kms/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kms`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_kms::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_kms::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_kms::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_kms::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_kms::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_kms`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/kms/src/config/endpoint.rs b/sdk/kms/src/config/endpoint.rs index 5514074abf20..6df421049e95 100644 --- a/sdk/kms/src/config/endpoint.rs +++ b/sdk/kms/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region af-south-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-northeast-3 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ap-south-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region ap-southeast-2 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region ap-southeast-3 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-central-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-south-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region eu-west-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region eu-west-2 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region eu-west-3 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region me-south-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region sa-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -849,7 +810,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -891,7 +850,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -912,7 +870,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -933,7 +890,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +910,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -975,7 +930,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -996,7 +950,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -1017,7 +970,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1038,7 +990,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1059,7 +1010,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -1080,7 +1030,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1101,7 +1050,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1122,7 +1070,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1143,7 +1090,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -1164,7 +1110,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1185,7 +1130,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1206,7 +1150,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1227,7 +1170,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1248,7 +1190,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -1269,7 +1210,6 @@ mod test { /// For region us-iso-west-1 with FIPS enabled and DualStack disabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(true) @@ -1290,7 +1230,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1309,7 +1248,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1325,7 +1263,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1346,7 +1283,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1367,7 +1303,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1386,7 +1321,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1402,7 +1336,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1422,7 +1355,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1441,7 +1373,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1458,7 +1389,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1478,7 +1408,6 @@ mod test { /// Missing region #[test] fn test_72() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1487,6 +1416,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Key Management Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1523,27 +1516,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lakeformation/src/config.rs b/sdk/lakeformation/src/config.rs index 702f5f27b473..a8294e0e1a94 100644 --- a/sdk/lakeformation/src/config.rs +++ b/sdk/lakeformation/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lakeformation`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lakeformation::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lakeformation::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lakeformation::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lakeformation::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lakeformation::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lakeformation`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lakeformation/src/config/endpoint.rs b/sdk/lakeformation/src/config/endpoint.rs index 77cfa808347e..e12ce01a0bdc 100644 --- a/sdk/lakeformation/src/config/endpoint.rs +++ b/sdk/lakeformation/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Lake Formation +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lambda/src/config.rs b/sdk/lambda/src/config.rs index bbf3a48221f8..3abccf8845d8 100644 --- a/sdk/lambda/src/config.rs +++ b/sdk/lambda/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lambda`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lambda::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lambda::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lambda::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lambda::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lambda::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lambda`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lambda/src/config/endpoint.rs b/sdk/lambda/src/config/endpoint.rs index 7f7bd7178649..dec57d256a61 100644 --- a/sdk/lambda/src/config/endpoint.rs +++ b/sdk/lambda/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -870,7 +830,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -912,7 +870,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -933,7 +890,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -954,7 +910,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -975,7 +930,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -996,7 +950,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -1017,7 +970,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +990,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -1059,7 +1010,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -1080,7 +1030,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -1101,7 +1050,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -1122,7 +1070,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1143,7 +1090,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1164,7 +1110,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1185,7 +1130,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1206,7 +1150,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1227,7 +1170,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -1248,7 +1190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1269,7 +1210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1290,7 +1230,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1311,7 +1250,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -1332,7 +1270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1351,7 +1288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1372,7 +1308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1388,7 +1323,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1409,7 +1343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1428,7 +1361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1449,7 +1381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1465,7 +1396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1485,7 +1415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_72() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1504,7 +1433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_73() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1521,7 +1449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_74() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1541,7 +1468,6 @@ mod test { /// Missing region #[test] fn test_75() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1550,6 +1476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Lambda +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1586,27 +1576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lexmodelbuilding/src/config.rs b/sdk/lexmodelbuilding/src/config.rs index b9b351eb05a8..22d2ec9bb235 100644 --- a/sdk/lexmodelbuilding/src/config.rs +++ b/sdk/lexmodelbuilding/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexmodelbuilding`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lexmodelbuilding::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lexmodelbuilding::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lexmodelbuilding::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lexmodelbuilding::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lexmodelbuilding::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexmodelbuilding`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lexmodelbuilding/src/config/endpoint.rs b/sdk/lexmodelbuilding/src/config/endpoint.rs index e4d1b473729a..76fd668200cf 100644 --- a/sdk/lexmodelbuilding/src/config/endpoint.rs +++ b/sdk/lexmodelbuilding/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lex Model Building Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lexmodelsv2/src/config.rs b/sdk/lexmodelsv2/src/config.rs index a1eafef35398..036080a08da8 100644 --- a/sdk/lexmodelsv2/src/config.rs +++ b/sdk/lexmodelsv2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexmodelsv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lexmodelsv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lexmodelsv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lexmodelsv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lexmodelsv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lexmodelsv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexmodelsv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lexmodelsv2/src/config/endpoint.rs b/sdk/lexmodelsv2/src/config/endpoint.rs index 22807e34d5a9..ef3e0c06268a 100644 --- a/sdk/lexmodelsv2/src/config/endpoint.rs +++ b/sdk/lexmodelsv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lex Model Building V2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lexruntime/src/config.rs b/sdk/lexruntime/src/config.rs index ee1c4c147adb..b8d7dc3fc1e9 100644 --- a/sdk/lexruntime/src/config.rs +++ b/sdk/lexruntime/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexruntime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lexruntime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lexruntime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lexruntime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lexruntime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lexruntime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexruntime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lexruntime/src/config/endpoint.rs b/sdk/lexruntime/src/config/endpoint.rs index 8dc827f139ec..0b87786e9daf 100644 --- a/sdk/lexruntime/src/config/endpoint.rs +++ b/sdk/lexruntime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lex Runtime Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lexruntimev2/src/config.rs b/sdk/lexruntimev2/src/config.rs index 817134950140..9a657b79f845 100644 --- a/sdk/lexruntimev2/src/config.rs +++ b/sdk/lexruntimev2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexruntimev2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lexruntimev2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lexruntimev2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lexruntimev2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lexruntimev2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lexruntimev2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lexruntimev2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lexruntimev2/src/config/endpoint.rs b/sdk/lexruntimev2/src/config/endpoint.rs index 69e333e29283..11ba18f41d71 100644 --- a/sdk/lexruntimev2/src/config/endpoint.rs +++ b/sdk/lexruntimev2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lex Runtime V2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/licensemanager/src/config.rs b/sdk/licensemanager/src/config.rs index e8bed68af400..03235b1f8d82 100644 --- a/sdk/licensemanager/src/config.rs +++ b/sdk/licensemanager/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_licensemanager`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_licensemanager::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_licensemanager::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_licensemanager::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_licensemanager::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_licensemanager::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_licensemanager`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/licensemanager/src/config/endpoint.rs b/sdk/licensemanager/src/config/endpoint.rs index 08eaf62b983d..d721080f713c 100644 --- a/sdk/licensemanager/src/config/endpoint.rs +++ b/sdk/licensemanager/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS License Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/licensemanagerlinuxsubscriptions/src/config.rs b/sdk/licensemanagerlinuxsubscriptions/src/config.rs index dba3d5dc12bc..3af4e1363629 100644 --- a/sdk/licensemanagerlinuxsubscriptions/src/config.rs +++ b/sdk/licensemanagerlinuxsubscriptions/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_licensemanagerlinuxsubscriptions`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_licensemanagerlinuxsubscriptions::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_licensemanagerlinuxsubscriptions::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_licensemanagerlinuxsubscriptions::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_licensemanagerlinuxsubscriptions::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_licensemanagerlinuxsubscriptions::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_licensemanagerlinuxsubscriptions`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/licensemanagerlinuxsubscriptions/src/config/endpoint.rs b/sdk/licensemanagerlinuxsubscriptions/src/config/endpoint.rs index 746fe3a6039c..586471ab8955 100644 --- a/sdk/licensemanagerlinuxsubscriptions/src/config/endpoint.rs +++ b/sdk/licensemanagerlinuxsubscriptions/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -115,7 +111,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -136,7 +131,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -158,7 +152,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -179,7 +172,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -200,7 +192,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -221,7 +212,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -242,7 +232,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -263,7 +252,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -319,7 +305,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -340,7 +325,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -396,7 +378,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -417,7 +398,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -437,7 +417,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -473,7 +451,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -493,7 +470,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -502,6 +478,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS License Manager Linux Subscriptions +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -538,27 +578,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/licensemanagerusersubscriptions/src/config.rs b/sdk/licensemanagerusersubscriptions/src/config.rs index 38234cb52c05..3c6e0cf26156 100644 --- a/sdk/licensemanagerusersubscriptions/src/config.rs +++ b/sdk/licensemanagerusersubscriptions/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_licensemanagerusersubscriptions`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_licensemanagerusersubscriptions::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_licensemanagerusersubscriptions::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_licensemanagerusersubscriptions::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_licensemanagerusersubscriptions::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_licensemanagerusersubscriptions::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_licensemanagerusersubscriptions`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/licensemanagerusersubscriptions/src/config/endpoint.rs b/sdk/licensemanagerusersubscriptions/src/config/endpoint.rs index 158656802e03..a0a0ef152679 100644 --- a/sdk/licensemanagerusersubscriptions/src/config/endpoint.rs +++ b/sdk/licensemanagerusersubscriptions/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -115,7 +111,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -136,7 +131,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -157,7 +151,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -178,7 +171,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -199,7 +191,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -220,7 +211,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -241,7 +231,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -262,7 +251,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -281,7 +269,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -302,7 +289,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -318,7 +304,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -339,7 +324,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -358,7 +342,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -379,7 +362,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -395,7 +377,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -416,7 +397,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -455,7 +434,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -472,7 +450,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +469,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -501,6 +477,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS License Manager User Subscriptions +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -537,27 +577,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lightsail/src/config.rs b/sdk/lightsail/src/config.rs index 62b49ba1b262..afcfc69ac1d9 100644 --- a/sdk/lightsail/src/config.rs +++ b/sdk/lightsail/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lightsail`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lightsail::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lightsail::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lightsail::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lightsail::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lightsail::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lightsail`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lightsail/src/config/endpoint.rs b/sdk/lightsail/src/config/endpoint.rs index 08034f127489..bbe27d5edb9d 100644 --- a/sdk/lightsail/src/config/endpoint.rs +++ b/sdk/lightsail/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -708,7 +675,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -727,7 +693,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -744,7 +709,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -764,7 +728,6 @@ mod test { /// Missing region #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -773,6 +736,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lightsail +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -809,27 +836,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/location/src/config.rs b/sdk/location/src/config.rs index f82d4e9d5f8b..1d8e220df775 100644 --- a/sdk/location/src/config.rs +++ b/sdk/location/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_location`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_location::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_location::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_location::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_location::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_location::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_location`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/location/src/config/endpoint.rs b/sdk/location/src/config/endpoint.rs index 50563b3d948f..8179755aa3c7 100644 --- a/sdk/location/src/config/endpoint.rs +++ b/sdk/location/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Location Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lookoutequipment/src/config.rs b/sdk/lookoutequipment/src/config.rs index 51aaa986b404..7f67dbac28b6 100644 --- a/sdk/lookoutequipment/src/config.rs +++ b/sdk/lookoutequipment/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lookoutequipment`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lookoutequipment::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lookoutequipment::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lookoutequipment::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lookoutequipment::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lookoutequipment::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lookoutequipment`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lookoutequipment/src/config/endpoint.rs b/sdk/lookoutequipment/src/config/endpoint.rs index 823764f8bfd4..5c29e93bcf7d 100644 --- a/sdk/lookoutequipment/src/config/endpoint.rs +++ b/sdk/lookoutequipment/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lookout for Equipment +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lookoutmetrics/src/config.rs b/sdk/lookoutmetrics/src/config.rs index b366a163dd3b..10a48c29e7c9 100644 --- a/sdk/lookoutmetrics/src/config.rs +++ b/sdk/lookoutmetrics/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lookoutmetrics`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lookoutmetrics::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lookoutmetrics::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lookoutmetrics::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lookoutmetrics::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lookoutmetrics::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lookoutmetrics`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lookoutmetrics/src/config/endpoint.rs b/sdk/lookoutmetrics/src/config/endpoint.rs index 1e09a590bb2b..1587f813c63d 100644 --- a/sdk/lookoutmetrics/src/config/endpoint.rs +++ b/sdk/lookoutmetrics/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -603,7 +575,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -622,7 +593,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -639,7 +609,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -659,7 +628,6 @@ mod test { /// Missing region #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -668,6 +636,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lookout for Metrics +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -704,27 +736,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/lookoutvision/src/config.rs b/sdk/lookoutvision/src/config.rs index 2e7363df0155..c95f839c034d 100644 --- a/sdk/lookoutvision/src/config.rs +++ b/sdk/lookoutvision/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lookoutvision`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_lookoutvision::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_lookoutvision::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_lookoutvision::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_lookoutvision::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_lookoutvision::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_lookoutvision`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/lookoutvision/src/config/endpoint.rs b/sdk/lookoutvision/src/config/endpoint.rs index 29682a794d9c..f155323c6bc5 100644 --- a/sdk/lookoutvision/src/config/endpoint.rs +++ b/sdk/lookoutvision/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Lookout for Vision +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/m2/src/config.rs b/sdk/m2/src/config.rs index eb5d02ad5ddb..be24b0579768 100644 --- a/sdk/m2/src/config.rs +++ b/sdk/m2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_m2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_m2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_m2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_m2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_m2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_m2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_m2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/m2/src/config/endpoint.rs b/sdk/m2/src/config/endpoint.rs index 9b32f9c584f3..a2630ffdc6d3 100644 --- a/sdk/m2/src/config/endpoint.rs +++ b/sdk/m2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWSMainframeModernization +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/machinelearning/src/config.rs b/sdk/machinelearning/src/config.rs index 84c3dce51849..6f29fbedfbf6 100644 --- a/sdk/machinelearning/src/config.rs +++ b/sdk/machinelearning/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_machinelearning`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_machinelearning::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_machinelearning::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_machinelearning::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_machinelearning::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_machinelearning::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_machinelearning`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/machinelearning/src/config/endpoint.rs b/sdk/machinelearning/src/config/endpoint.rs index 3ae0001365fd..33183399ac05 100644 --- a/sdk/machinelearning/src/config/endpoint.rs +++ b/sdk/machinelearning/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Machine Learning +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/macie/src/config.rs b/sdk/macie/src/config.rs index d16a76a6a565..2860fd878e8b 100644 --- a/sdk/macie/src/config.rs +++ b/sdk/macie/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_macie`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_macie::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_macie::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_macie::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_macie::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_macie::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_macie`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/macie/src/config/endpoint.rs b/sdk/macie/src/config/endpoint.rs index 3eae4e5f31a4..81a88548289b 100644 --- a/sdk/macie/src/config/endpoint.rs +++ b/sdk/macie/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Macie +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/macie2/src/config.rs b/sdk/macie2/src/config.rs index c42b790abe28..9fdd626d9ad7 100644 --- a/sdk/macie2/src/config.rs +++ b/sdk/macie2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_macie2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_macie2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_macie2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_macie2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_macie2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_macie2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_macie2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/macie2/src/config/endpoint.rs b/sdk/macie2/src/config/endpoint.rs index 6e9b3cf25e93..b4af144e6b95 100644 --- a/sdk/macie2/src/config/endpoint.rs +++ b/sdk/macie2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -918,7 +875,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -937,7 +893,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +909,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -974,7 +928,6 @@ mod test { /// Missing region #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -983,6 +936,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Macie 2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1019,27 +1036,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/managedblockchain/src/config.rs b/sdk/managedblockchain/src/config.rs index cc52796017f0..766401c09677 100644 --- a/sdk/managedblockchain/src/config.rs +++ b/sdk/managedblockchain/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_managedblockchain`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_managedblockchain::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_managedblockchain::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_managedblockchain::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_managedblockchain::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_managedblockchain::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_managedblockchain`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/managedblockchain/src/config/endpoint.rs b/sdk/managedblockchain/src/config/endpoint.rs index 372cc9ad7f72..9771bd04093c 100644 --- a/sdk/managedblockchain/src/config/endpoint.rs +++ b/sdk/managedblockchain/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Managed Blockchain +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/managedblockchainquery/src/config.rs b/sdk/managedblockchainquery/src/config.rs index 81cf5a389620..2ec38a54a812 100644 --- a/sdk/managedblockchainquery/src/config.rs +++ b/sdk/managedblockchainquery/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_managedblockchainquery`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_managedblockchainquery::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_managedblockchainquery::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_managedblockchainquery::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_managedblockchainquery::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_managedblockchainquery::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_managedblockchainquery`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/managedblockchainquery/src/config/endpoint.rs b/sdk/managedblockchainquery/src/config/endpoint.rs index c01cc46b3e02..b326fb28cee3 100644 --- a/sdk/managedblockchainquery/src/config/endpoint.rs +++ b/sdk/managedblockchainquery/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Managed Blockchain Query +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/marketplacecatalog/src/config.rs b/sdk/marketplacecatalog/src/config.rs index d51b918e2b40..7e877389f1c0 100644 --- a/sdk/marketplacecatalog/src/config.rs +++ b/sdk/marketplacecatalog/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplacecatalog`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_marketplacecatalog::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_marketplacecatalog::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_marketplacecatalog::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_marketplacecatalog::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_marketplacecatalog::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplacecatalog`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/marketplacecatalog/src/config/endpoint.rs b/sdk/marketplacecatalog/src/config/endpoint.rs index cb92e1a1c3e9..d449a683caa2 100644 --- a/sdk/marketplacecatalog/src/config/endpoint.rs +++ b/sdk/marketplacecatalog/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Marketplace Catalog Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/marketplacecommerceanalytics/src/config.rs b/sdk/marketplacecommerceanalytics/src/config.rs index cec912eb72bc..2c853d80a92b 100644 --- a/sdk/marketplacecommerceanalytics/src/config.rs +++ b/sdk/marketplacecommerceanalytics/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplacecommerceanalytics`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_marketplacecommerceanalytics::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_marketplacecommerceanalytics::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_marketplacecommerceanalytics::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_marketplacecommerceanalytics::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_marketplacecommerceanalytics::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplacecommerceanalytics`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/marketplacecommerceanalytics/src/config/endpoint.rs b/sdk/marketplacecommerceanalytics/src/config/endpoint.rs index 24ff3c37bbad..a029c59e0b6c 100644 --- a/sdk/marketplacecommerceanalytics/src/config/endpoint.rs +++ b/sdk/marketplacecommerceanalytics/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Marketplace Commerce Analytics +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/marketplaceentitlement/src/config.rs b/sdk/marketplaceentitlement/src/config.rs index 476fc7b1b80e..0aee188ade8c 100644 --- a/sdk/marketplaceentitlement/src/config.rs +++ b/sdk/marketplaceentitlement/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplaceentitlement`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_marketplaceentitlement::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_marketplaceentitlement::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_marketplaceentitlement::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_marketplaceentitlement::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_marketplaceentitlement::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplaceentitlement`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/marketplaceentitlement/src/config/endpoint.rs b/sdk/marketplaceentitlement/src/config/endpoint.rs index b9fb4a92f4fe..f04442851b5a 100644 --- a/sdk/marketplaceentitlement/src/config/endpoint.rs +++ b/sdk/marketplaceentitlement/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Marketplace Entitlement Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/marketplacemetering/src/config.rs b/sdk/marketplacemetering/src/config.rs index dc7b92ed87fb..530c0011c71e 100644 --- a/sdk/marketplacemetering/src/config.rs +++ b/sdk/marketplacemetering/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplacemetering`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_marketplacemetering::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_marketplacemetering::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_marketplacemetering::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_marketplacemetering::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_marketplacemetering::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_marketplacemetering`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/marketplacemetering/src/config/endpoint.rs b/sdk/marketplacemetering/src/config/endpoint.rs index af0b99ae6f49..2ba6163c91a2 100644 --- a/sdk/marketplacemetering/src/config/endpoint.rs +++ b/sdk/marketplacemetering/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWSMarketplace Metering +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediaconnect/src/config.rs b/sdk/mediaconnect/src/config.rs index 13fba8498146..1fb926c4fd01 100644 --- a/sdk/mediaconnect/src/config.rs +++ b/sdk/mediaconnect/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediaconnect`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediaconnect::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediaconnect::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediaconnect::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediaconnect::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediaconnect::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediaconnect`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediaconnect/src/config/endpoint.rs b/sdk/mediaconnect/src/config/endpoint.rs index e15cb7556716..52c79330f1bf 100644 --- a/sdk/mediaconnect/src/config/endpoint.rs +++ b/sdk/mediaconnect/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS MediaConnect +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediaconvert/src/config.rs b/sdk/mediaconvert/src/config.rs index 09953a03c094..79ec6fffb371 100644 --- a/sdk/mediaconvert/src/config.rs +++ b/sdk/mediaconvert/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediaconvert`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediaconvert::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediaconvert::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediaconvert::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediaconvert::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediaconvert::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediaconvert`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediaconvert/src/config/endpoint.rs b/sdk/mediaconvert/src/config/endpoint.rs index d658824f521a..6daa63999dbc 100644 --- a/sdk/mediaconvert/src/config/endpoint.rs +++ b/sdk/mediaconvert/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elemental MediaConvert +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/medialive/src/config.rs b/sdk/medialive/src/config.rs index 50080f61b07f..a6c288b62f71 100644 --- a/sdk/medialive/src/config.rs +++ b/sdk/medialive/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_medialive`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_medialive::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_medialive::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_medialive::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_medialive::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_medialive::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_medialive`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/medialive/src/config/endpoint.rs b/sdk/medialive/src/config/endpoint.rs index f7797ff40ce6..14bbedc171dd 100644 --- a/sdk/medialive/src/config/endpoint.rs +++ b/sdk/medialive/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elemental MediaLive +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediapackage/src/config.rs b/sdk/mediapackage/src/config.rs index 5bb23cc7b301..158132891fcd 100644 --- a/sdk/mediapackage/src/config.rs +++ b/sdk/mediapackage/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediapackage`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediapackage::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediapackage::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediapackage::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediapackage::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediapackage::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediapackage`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediapackage/src/config/endpoint.rs b/sdk/mediapackage/src/config/endpoint.rs index f6e0527388e4..2d814f947958 100644 --- a/sdk/mediapackage/src/config/endpoint.rs +++ b/sdk/mediapackage/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -729,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -748,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -765,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -785,7 +748,6 @@ mod test { /// Missing region #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -794,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elemental MediaPackage +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -830,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediapackagev2/src/config.rs b/sdk/mediapackagev2/src/config.rs index fea21d39e434..3cdbf3d8e316 100644 --- a/sdk/mediapackagev2/src/config.rs +++ b/sdk/mediapackagev2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediapackagev2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediapackagev2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediapackagev2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediapackagev2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediapackagev2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediapackagev2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediapackagev2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediapackagev2/src/config/endpoint.rs b/sdk/mediapackagev2/src/config/endpoint.rs index 5506f0a4c118..535010298321 100644 --- a/sdk/mediapackagev2/src/config/endpoint.rs +++ b/sdk/mediapackagev2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elemental MediaPackage v2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediapackagevod/src/config.rs b/sdk/mediapackagevod/src/config.rs index 5e4f4c30fba6..ddd30b974aa7 100644 --- a/sdk/mediapackagevod/src/config.rs +++ b/sdk/mediapackagevod/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediapackagevod`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediapackagevod::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediapackagevod::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediapackagevod::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediapackagevod::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediapackagevod::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediapackagevod`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediapackagevod/src/config/endpoint.rs b/sdk/mediapackagevod/src/config/endpoint.rs index 733e22296136..cf99e49a44f8 100644 --- a/sdk/mediapackagevod/src/config/endpoint.rs +++ b/sdk/mediapackagevod/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -729,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -748,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -765,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -785,7 +748,6 @@ mod test { /// Missing region #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -794,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elemental MediaPackage VOD +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -830,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediastore/src/config.rs b/sdk/mediastore/src/config.rs index ce4ae6fcf179..1f02f9f2544e 100644 --- a/sdk/mediastore/src/config.rs +++ b/sdk/mediastore/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediastore`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediastore::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediastore::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediastore::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediastore::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediastore::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediastore`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediastore/src/config/endpoint.rs b/sdk/mediastore/src/config/endpoint.rs index 6d329259d7f6..8743b917377e 100644 --- a/sdk/mediastore/src/config/endpoint.rs +++ b/sdk/mediastore/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -603,7 +575,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -622,7 +593,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -639,7 +609,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -659,7 +628,6 @@ mod test { /// Missing region #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -668,6 +636,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elemental MediaStore +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -704,27 +736,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediastoredata/src/config.rs b/sdk/mediastoredata/src/config.rs index 49199d421ae2..b11152d3a5b8 100644 --- a/sdk/mediastoredata/src/config.rs +++ b/sdk/mediastoredata/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediastoredata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediastoredata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediastoredata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediastoredata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediastoredata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediastoredata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediastoredata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediastoredata/src/config/endpoint.rs b/sdk/mediastoredata/src/config/endpoint.rs index 64754a5e732e..1d37598d6ddf 100644 --- a/sdk/mediastoredata/src/config/endpoint.rs +++ b/sdk/mediastoredata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -603,7 +575,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -622,7 +593,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -639,7 +609,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -659,7 +628,6 @@ mod test { /// Missing region #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -668,6 +636,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Elemental MediaStore Data Plane +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -704,27 +736,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mediatailor/src/config.rs b/sdk/mediatailor/src/config.rs index 8152ab81b457..e522c8ea6bfc 100644 --- a/sdk/mediatailor/src/config.rs +++ b/sdk/mediatailor/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediatailor`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mediatailor::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mediatailor::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mediatailor::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mediatailor::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mediatailor::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mediatailor`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mediatailor/src/config/endpoint.rs b/sdk/mediatailor/src/config/endpoint.rs index 2f3a7bb6e5be..f837b9cb8b75 100644 --- a/sdk/mediatailor/src/config/endpoint.rs +++ b/sdk/mediatailor/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS MediaTailor +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/medicalimaging/src/config.rs b/sdk/medicalimaging/src/config.rs index 1070dee10276..22502f1a0ecf 100644 --- a/sdk/medicalimaging/src/config.rs +++ b/sdk/medicalimaging/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_medicalimaging`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_medicalimaging::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_medicalimaging::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_medicalimaging::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_medicalimaging::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_medicalimaging::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_medicalimaging`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/medicalimaging/src/config/endpoint.rs b/sdk/medicalimaging/src/config/endpoint.rs index 4afe1877662a..0807b40182fb 100644 --- a/sdk/medicalimaging/src/config/endpoint.rs +++ b/sdk/medicalimaging/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Health Imaging +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/memorydb/src/config.rs b/sdk/memorydb/src/config.rs index 1bf68ae4b31d..24d96b9f9f16 100644 --- a/sdk/memorydb/src/config.rs +++ b/sdk/memorydb/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_memorydb`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_memorydb::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_memorydb::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_memorydb::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_memorydb::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_memorydb::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_memorydb`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/memorydb/src/config/endpoint.rs b/sdk/memorydb/src/config/endpoint.rs index c6f839133b10..4c10a4092080 100644 --- a/sdk/memorydb/src/config/endpoint.rs +++ b/sdk/memorydb/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region fips with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("fips".to_string()) .use_fips(false) @@ -271,7 +260,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -292,7 +280,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -313,7 +300,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -334,7 +320,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -355,7 +340,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -376,7 +360,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -397,7 +380,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -418,7 +400,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -439,7 +420,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -460,7 +440,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -481,7 +460,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -502,7 +480,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -523,7 +500,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -544,7 +520,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -565,7 +540,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -586,7 +560,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -607,7 +580,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -628,7 +600,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -647,7 +618,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -668,7 +638,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -684,7 +653,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -705,7 +673,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -724,7 +691,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -745,7 +711,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -761,7 +726,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -782,7 +746,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -802,7 +765,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -821,7 +783,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -838,7 +799,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -858,7 +818,6 @@ mod test { /// Missing region #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -867,6 +826,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon MemoryDB +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -903,27 +926,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mgn/src/config.rs b/sdk/mgn/src/config.rs index 042667e1dcbe..90cc5b2f38b0 100644 --- a/sdk/mgn/src/config.rs +++ b/sdk/mgn/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mgn`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mgn::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mgn::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mgn::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mgn::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mgn::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mgn`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mgn/src/config/endpoint.rs b/sdk/mgn/src/config/endpoint.rs index feff5603cec6..a66a9973a06e 100644 --- a/sdk/mgn/src/config/endpoint.rs +++ b/sdk/mgn/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to Application Migration Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/migrationhub/src/config.rs b/sdk/migrationhub/src/config.rs index 2ac10a7de4dc..460e5cf0db6c 100644 --- a/sdk/migrationhub/src/config.rs +++ b/sdk/migrationhub/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhub`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_migrationhub::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_migrationhub::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_migrationhub::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_migrationhub::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_migrationhub::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhub`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/migrationhub/src/config/endpoint.rs b/sdk/migrationhub/src/config/endpoint.rs index 318b87ecd3da..0ac2b9b70f16 100644 --- a/sdk/migrationhub/src/config/endpoint.rs +++ b/sdk/migrationhub/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Migration Hub +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/migrationhubconfig/src/config.rs b/sdk/migrationhubconfig/src/config.rs index a99b4a1f3805..0860d08e6716 100644 --- a/sdk/migrationhubconfig/src/config.rs +++ b/sdk/migrationhubconfig/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhubconfig`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_migrationhubconfig::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_migrationhubconfig::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_migrationhubconfig::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_migrationhubconfig::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_migrationhubconfig::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhubconfig`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/migrationhubconfig/src/config/endpoint.rs b/sdk/migrationhubconfig/src/config/endpoint.rs index ce4a26020746..36943ca2d677 100644 --- a/sdk/migrationhubconfig/src/config/endpoint.rs +++ b/sdk/migrationhubconfig/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Migration Hub Config +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/migrationhuborchestrator/src/config.rs b/sdk/migrationhuborchestrator/src/config.rs index 6b700063fa60..b445f4ccf3d5 100644 --- a/sdk/migrationhuborchestrator/src/config.rs +++ b/sdk/migrationhuborchestrator/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhuborchestrator`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_migrationhuborchestrator::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_migrationhuborchestrator::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_migrationhuborchestrator::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_migrationhuborchestrator::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_migrationhuborchestrator::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhuborchestrator`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/migrationhuborchestrator/src/config/endpoint.rs b/sdk/migrationhuborchestrator/src/config/endpoint.rs index e41c596e27f4..f1507d5ca2ed 100644 --- a/sdk/migrationhuborchestrator/src/config/endpoint.rs +++ b/sdk/migrationhuborchestrator/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Migration Hub Orchestrator +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/migrationhubrefactorspaces/src/config.rs b/sdk/migrationhubrefactorspaces/src/config.rs index 6fb9b7c8eda3..3a10d41ea10f 100644 --- a/sdk/migrationhubrefactorspaces/src/config.rs +++ b/sdk/migrationhubrefactorspaces/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhubrefactorspaces`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_migrationhubrefactorspaces::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_migrationhubrefactorspaces::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_migrationhubrefactorspaces::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_migrationhubrefactorspaces::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_migrationhubrefactorspaces::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhubrefactorspaces`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/migrationhubrefactorspaces/src/config/endpoint.rs b/sdk/migrationhubrefactorspaces/src/config/endpoint.rs index 162cdddc121c..f4cdaa3d1374 100644 --- a/sdk/migrationhubrefactorspaces/src/config/endpoint.rs +++ b/sdk/migrationhubrefactorspaces/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Migration Hub Refactor Spaces +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/migrationhubstrategy/src/config.rs b/sdk/migrationhubstrategy/src/config.rs index ee1b7fe97970..f495cbbab19b 100644 --- a/sdk/migrationhubstrategy/src/config.rs +++ b/sdk/migrationhubstrategy/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhubstrategy`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_migrationhubstrategy::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_migrationhubstrategy::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_migrationhubstrategy::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_migrationhubstrategy::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_migrationhubstrategy::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_migrationhubstrategy`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/migrationhubstrategy/src/config/endpoint.rs b/sdk/migrationhubstrategy/src/config/endpoint.rs index 74f62519471b..67feade6f079 100644 --- a/sdk/migrationhubstrategy/src/config/endpoint.rs +++ b/sdk/migrationhubstrategy/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to Migration Hub Strategy Recommendations +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mobile/src/config.rs b/sdk/mobile/src/config.rs index 93a649cbd312..8d5113ca2309 100644 --- a/sdk/mobile/src/config.rs +++ b/sdk/mobile/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mobile`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mobile::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mobile::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mobile::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mobile::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mobile::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mobile`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mobile/src/config/endpoint.rs b/sdk/mobile/src/config/endpoint.rs index 778c94f3aabc..001d11352352 100644 --- a/sdk/mobile/src/config/endpoint.rs +++ b/sdk/mobile/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Mobile +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mq/src/config.rs b/sdk/mq/src/config.rs index 6d81837a45d1..1dd3b62bd432 100644 --- a/sdk/mq/src/config.rs +++ b/sdk/mq/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mq`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mq::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mq::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mq::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mq::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mq::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mq`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mq/src/config/endpoint.rs b/sdk/mq/src/config/endpoint.rs index 2dad7ed35d5b..a71c49314c83 100644 --- a/sdk/mq/src/config/endpoint.rs +++ b/sdk/mq/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AmazonMQ +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mturk/src/config.rs b/sdk/mturk/src/config.rs index 732254689f8d..985fa4153c64 100644 --- a/sdk/mturk/src/config.rs +++ b/sdk/mturk/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mturk`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mturk::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mturk::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mturk::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mturk::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mturk::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mturk`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mturk/src/config/endpoint.rs b/sdk/mturk/src/config/endpoint.rs index af2f0bed2be6..3282743a030f 100644 --- a/sdk/mturk/src/config/endpoint.rs +++ b/sdk/mturk/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region sandbox with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sandbox".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Mechanical Turk +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/mwaa/src/config.rs b/sdk/mwaa/src/config.rs index 7ae05157bb5e..566ba117d6b6 100644 --- a/sdk/mwaa/src/config.rs +++ b/sdk/mwaa/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mwaa`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_mwaa::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_mwaa::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_mwaa::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_mwaa::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_mwaa::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_mwaa`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/mwaa/src/config/endpoint.rs b/sdk/mwaa/src/config/endpoint.rs index b9354c82bb52..d0bae63d59e4 100644 --- a/sdk/mwaa/src/config/endpoint.rs +++ b/sdk/mwaa/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -729,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -748,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -765,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -785,7 +748,6 @@ mod test { /// Missing region #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -794,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to AmazonMWAA +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -830,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/neptune/src/config.rs b/sdk/neptune/src/config.rs index a4ab218f0291..476617bb3d31 100644 --- a/sdk/neptune/src/config.rs +++ b/sdk/neptune/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_neptune`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_neptune::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_neptune::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_neptune::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_neptune::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_neptune::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_neptune`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/neptune/src/config/endpoint.rs b/sdk/neptune/src/config/endpoint.rs index b7d06d90ca29..cc561a815124 100644 --- a/sdk/neptune/src/config/endpoint.rs +++ b/sdk/neptune/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -931,7 +888,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -968,7 +923,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1008,7 +961,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1024,7 +976,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1044,7 +995,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1063,7 +1013,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1080,7 +1029,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1100,7 +1048,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1109,6 +1056,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Neptune +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1145,27 +1156,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/neptunedata/src/config.rs b/sdk/neptunedata/src/config.rs index a131a2c818bb..73e4e315ffa8 100644 --- a/sdk/neptunedata/src/config.rs +++ b/sdk/neptunedata/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_neptunedata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_neptunedata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_neptunedata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_neptunedata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_neptunedata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_neptunedata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_neptunedata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/neptunedata/src/config/endpoint.rs b/sdk/neptunedata/src/config/endpoint.rs index 85169c812cf2..d50fac4d9d81 100644 --- a/sdk/neptunedata/src/config/endpoint.rs +++ b/sdk/neptunedata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon NeptuneData +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/networkfirewall/src/config.rs b/sdk/networkfirewall/src/config.rs index 8513959e6e0f..b2282c44c4f0 100644 --- a/sdk/networkfirewall/src/config.rs +++ b/sdk/networkfirewall/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_networkfirewall`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_networkfirewall::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_networkfirewall::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_networkfirewall::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_networkfirewall::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_networkfirewall::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_networkfirewall`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/networkfirewall/src/config/endpoint.rs b/sdk/networkfirewall/src/config/endpoint.rs index bf79dc81fb2a..d590ea34020b 100644 --- a/sdk/networkfirewall/src/config/endpoint.rs +++ b/sdk/networkfirewall/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Network Firewall +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/networkmanager/src/config.rs b/sdk/networkmanager/src/config.rs index 00a963ad3575..03becf92e110 100644 --- a/sdk/networkmanager/src/config.rs +++ b/sdk/networkmanager/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_networkmanager`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_networkmanager::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_networkmanager::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_networkmanager::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_networkmanager::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_networkmanager::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_networkmanager`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/networkmanager/src/config/endpoint.rs b/sdk/networkmanager/src/config/endpoint.rs index c32298848a3d..3193c049c084 100644 --- a/sdk/networkmanager/src/config/endpoint.rs +++ b/sdk/networkmanager/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -155,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -176,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -197,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -218,7 +210,6 @@ mod test { /// For region aws-us-gov-global with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(false) @@ -249,7 +240,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -270,7 +260,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -291,7 +280,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -312,7 +300,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -343,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -362,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -383,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -399,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -420,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -439,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -460,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -476,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -497,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -517,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -536,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -553,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -573,7 +548,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -582,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Network Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -618,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/nimble/src/config.rs b/sdk/nimble/src/config.rs index 30ca9843cdf8..1b1eea537d9a 100644 --- a/sdk/nimble/src/config.rs +++ b/sdk/nimble/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_nimble`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_nimble::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_nimble::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_nimble::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_nimble::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_nimble::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_nimble`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/nimble/src/config/endpoint.rs b/sdk/nimble/src/config/endpoint.rs index 15cf7b5a5fc5..5a23fac8a0f1 100644 --- a/sdk/nimble/src/config/endpoint.rs +++ b/sdk/nimble/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to AmazonNimbleStudio +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/oam/src/config.rs b/sdk/oam/src/config.rs index 338c18734182..ddc5b9638bf7 100644 --- a/sdk/oam/src/config.rs +++ b/sdk/oam/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_oam`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_oam::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_oam::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_oam::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_oam::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_oam::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_oam`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/oam/src/config/endpoint.rs b/sdk/oam/src/config/endpoint.rs index d9f486559f6b..5f7be72271d4 100644 --- a/sdk/oam/src/config/endpoint.rs +++ b/sdk/oam/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to CloudWatch Observability Access Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/omics/src/config.rs b/sdk/omics/src/config.rs index 8ffc08c0234c..43524b02a36c 100644 --- a/sdk/omics/src/config.rs +++ b/sdk/omics/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_omics`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_omics::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_omics::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_omics::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_omics::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_omics::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_omics`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/omics/src/config/endpoint.rs b/sdk/omics/src/config/endpoint.rs index fc271083ace2..92b3a68a591d 100644 --- a/sdk/omics/src/config/endpoint.rs +++ b/sdk/omics/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Omics +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/opensearch/src/config.rs b/sdk/opensearch/src/config.rs index 7ae7c4e47ec0..030f92152d2d 100644 --- a/sdk/opensearch/src/config.rs +++ b/sdk/opensearch/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opensearch`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_opensearch::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_opensearch::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_opensearch::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_opensearch::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_opensearch::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opensearch`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/opensearch/src/config/endpoint.rs b/sdk/opensearch/src/config/endpoint.rs index 223c445b6073..436bdf89ff89 100644 --- a/sdk/opensearch/src/config/endpoint.rs +++ b/sdk/opensearch/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon OpenSearch Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/opensearchserverless/src/config.rs b/sdk/opensearchserverless/src/config.rs index 04b2d7db999b..e0c898dc0550 100644 --- a/sdk/opensearchserverless/src/config.rs +++ b/sdk/opensearchserverless/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opensearchserverless`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_opensearchserverless::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_opensearchserverless::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_opensearchserverless::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_opensearchserverless::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_opensearchserverless::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opensearchserverless`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/opensearchserverless/src/config/endpoint.rs b/sdk/opensearchserverless/src/config/endpoint.rs index e31c1eac2432..778e5e41affc 100644 --- a/sdk/opensearchserverless/src/config/endpoint.rs +++ b/sdk/opensearchserverless/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to OpenSearch Service Serverless +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/opsworks/src/config.rs b/sdk/opsworks/src/config.rs index e6e4a8821ba4..0e25b535f367 100644 --- a/sdk/opsworks/src/config.rs +++ b/sdk/opsworks/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opsworks`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_opsworks::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_opsworks::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_opsworks::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_opsworks::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_opsworks::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opsworks`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/opsworks/src/config/endpoint.rs b/sdk/opsworks/src/config/endpoint.rs index 1ff7371ac996..91a1da2f4c3a 100644 --- a/sdk/opsworks/src/config/endpoint.rs +++ b/sdk/opsworks/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -729,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -748,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -765,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -785,7 +748,6 @@ mod test { /// Missing region #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -794,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS OpsWorks +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -830,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/opsworkscm/src/config.rs b/sdk/opsworkscm/src/config.rs index 1e1090df8468..65356d088d54 100644 --- a/sdk/opsworkscm/src/config.rs +++ b/sdk/opsworkscm/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opsworkscm`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_opsworkscm::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_opsworkscm::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_opsworkscm::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_opsworkscm::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_opsworkscm::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_opsworkscm`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/opsworkscm/src/config/endpoint.rs b/sdk/opsworkscm/src/config/endpoint.rs index 0e285e146778..a1b23719a950 100644 --- a/sdk/opsworkscm/src/config/endpoint.rs +++ b/sdk/opsworkscm/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -603,7 +575,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -622,7 +593,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -639,7 +609,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -659,7 +628,6 @@ mod test { /// Missing region #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -668,6 +636,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS OpsWorks CM +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -704,27 +736,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/organizations/src/config.rs b/sdk/organizations/src/config.rs index c4c5190317fe..b97fae29f8c2 100644 --- a/sdk/organizations/src/config.rs +++ b/sdk/organizations/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_organizations`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_organizations::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_organizations::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_organizations::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_organizations::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_organizations::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_organizations`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/organizations/src/config/endpoint.rs b/sdk/organizations/src/config/endpoint.rs index a6270f91e12e..33ff105b9256 100644 --- a/sdk/organizations/src/config/endpoint.rs +++ b/sdk/organizations/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region aws-global with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -71,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -92,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -123,7 +120,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -144,7 +140,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -175,7 +170,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -206,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -227,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -248,7 +240,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -269,7 +260,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -300,7 +290,6 @@ mod test { /// For region aws-us-gov-global with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(false) @@ -331,7 +320,6 @@ mod test { /// For region aws-us-gov-global with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(true) @@ -362,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -383,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -414,7 +400,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -435,7 +420,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -466,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -485,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -506,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -522,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -543,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -562,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -583,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -599,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -620,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -640,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -659,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -676,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -696,7 +668,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -705,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Organizations +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -741,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/osis/src/config.rs b/sdk/osis/src/config.rs index f7a577ff6c66..594ad02e3bd1 100644 --- a/sdk/osis/src/config.rs +++ b/sdk/osis/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_osis`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_osis::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_osis::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_osis::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_osis::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_osis::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_osis`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/osis/src/config/endpoint.rs b/sdk/osis/src/config/endpoint.rs index c27f4ec7ea5a..2fc4e6e87d83 100644 --- a/sdk/osis/src/config/endpoint.rs +++ b/sdk/osis/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon OpenSearch Ingestion +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/outposts/src/config.rs b/sdk/outposts/src/config.rs index a2602ada6fbc..afc33776ce64 100644 --- a/sdk/outposts/src/config.rs +++ b/sdk/outposts/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_outposts`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_outposts::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_outposts::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_outposts::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_outposts::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_outposts::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_outposts`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/outposts/src/config/endpoint.rs b/sdk/outposts/src/config/endpoint.rs index 3974439e99bc..a51faf3908c6 100644 --- a/sdk/outposts/src/config/endpoint.rs +++ b/sdk/outposts/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Outposts +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/panorama/src/config.rs b/sdk/panorama/src/config.rs index b4406ee0181c..738bca650ad4 100644 --- a/sdk/panorama/src/config.rs +++ b/sdk/panorama/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_panorama`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_panorama::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_panorama::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_panorama::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_panorama::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_panorama::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_panorama`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/panorama/src/config/endpoint.rs b/sdk/panorama/src/config/endpoint.rs index a4ed02d02493..82443012370e 100644 --- a/sdk/panorama/src/config/endpoint.rs +++ b/sdk/panorama/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Panorama +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/paymentcryptography/src/config.rs b/sdk/paymentcryptography/src/config.rs index 22a97bb742f9..cefa72d189e7 100644 --- a/sdk/paymentcryptography/src/config.rs +++ b/sdk/paymentcryptography/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_paymentcryptography`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_paymentcryptography::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_paymentcryptography::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_paymentcryptography::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_paymentcryptography::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_paymentcryptography::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_paymentcryptography`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/paymentcryptography/src/config/endpoint.rs b/sdk/paymentcryptography/src/config/endpoint.rs index cd0f9258e6e4..77269efdc290 100644 --- a/sdk/paymentcryptography/src/config/endpoint.rs +++ b/sdk/paymentcryptography/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -115,7 +111,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -136,7 +131,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -157,7 +151,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -178,7 +171,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -199,7 +191,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -220,7 +211,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -241,7 +231,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -262,7 +251,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -281,7 +269,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -302,7 +289,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -318,7 +304,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -339,7 +324,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -358,7 +342,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -379,7 +362,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -395,7 +377,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -416,7 +397,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -455,7 +434,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -472,7 +450,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +469,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -501,6 +477,70 @@ mod test { } } +/// Endpoint resolver trait specific to Payment Cryptography Control Plane +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -537,27 +577,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/paymentcryptographydata/src/config.rs b/sdk/paymentcryptographydata/src/config.rs index e71d367ee0c4..b3e7ea1ded1a 100644 --- a/sdk/paymentcryptographydata/src/config.rs +++ b/sdk/paymentcryptographydata/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_paymentcryptographydata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_paymentcryptographydata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_paymentcryptographydata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_paymentcryptographydata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_paymentcryptographydata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_paymentcryptographydata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_paymentcryptographydata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/paymentcryptographydata/src/config/endpoint.rs b/sdk/paymentcryptographydata/src/config/endpoint.rs index 4a317017e476..c47d68a51d65 100644 --- a/sdk/paymentcryptographydata/src/config/endpoint.rs +++ b/sdk/paymentcryptographydata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -115,7 +111,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -136,7 +131,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -157,7 +151,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -178,7 +171,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -199,7 +191,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -220,7 +211,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -241,7 +231,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -262,7 +251,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -281,7 +269,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -302,7 +289,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -318,7 +304,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -339,7 +324,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -358,7 +342,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -379,7 +362,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -395,7 +377,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -416,7 +397,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -455,7 +434,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -472,7 +450,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +469,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -501,6 +477,70 @@ mod test { } } +/// Endpoint resolver trait specific to Payment Cryptography Data Plane +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -537,27 +577,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pcaconnectorad/src/config.rs b/sdk/pcaconnectorad/src/config.rs index bcbf32e63799..d49a0da6f247 100644 --- a/sdk/pcaconnectorad/src/config.rs +++ b/sdk/pcaconnectorad/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pcaconnectorad`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pcaconnectorad::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pcaconnectorad::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pcaconnectorad::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pcaconnectorad::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pcaconnectorad::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pcaconnectorad`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pcaconnectorad/src/config/endpoint.rs b/sdk/pcaconnectorad/src/config/endpoint.rs index 5151d6f9a8b3..fc8523901c1d 100644 --- a/sdk/pcaconnectorad/src/config/endpoint.rs +++ b/sdk/pcaconnectorad/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to PcaConnectorAd +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/personalize/src/config.rs b/sdk/personalize/src/config.rs index 6ba58e8f271f..f558ae04cddd 100644 --- a/sdk/personalize/src/config.rs +++ b/sdk/personalize/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_personalize`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_personalize::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_personalize::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_personalize::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_personalize::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_personalize::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_personalize`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/personalize/src/config/endpoint.rs b/sdk/personalize/src/config/endpoint.rs index 9139d334e4ab..ce5dbc937595 100644 --- a/sdk/personalize/src/config/endpoint.rs +++ b/sdk/personalize/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Personalize +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/personalizeevents/src/config.rs b/sdk/personalizeevents/src/config.rs index 3358b6a59811..7187bd8a872d 100644 --- a/sdk/personalizeevents/src/config.rs +++ b/sdk/personalizeevents/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_personalizeevents`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_personalizeevents::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_personalizeevents::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_personalizeevents::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_personalizeevents::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_personalizeevents::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_personalizeevents`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/personalizeevents/src/config/endpoint.rs b/sdk/personalizeevents/src/config/endpoint.rs index 3ac1e1f92cf1..b1a85c5596b5 100644 --- a/sdk/personalizeevents/src/config/endpoint.rs +++ b/sdk/personalizeevents/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Personalize Events +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/personalizeruntime/src/config.rs b/sdk/personalizeruntime/src/config.rs index f83001db997f..0a0debbdf324 100644 --- a/sdk/personalizeruntime/src/config.rs +++ b/sdk/personalizeruntime/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_personalizeruntime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_personalizeruntime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_personalizeruntime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_personalizeruntime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_personalizeruntime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_personalizeruntime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_personalizeruntime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/personalizeruntime/src/config/endpoint.rs b/sdk/personalizeruntime/src/config/endpoint.rs index 26c73864fb14..c59c09abeae9 100644 --- a/sdk/personalizeruntime/src/config/endpoint.rs +++ b/sdk/personalizeruntime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Personalize Runtime +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pi/src/config.rs b/sdk/pi/src/config.rs index 9e8ed037cbca..844bb97e4cf0 100644 --- a/sdk/pi/src/config.rs +++ b/sdk/pi/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pi`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pi::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pi::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pi::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pi::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pi::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pi`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pi/src/config/endpoint.rs b/sdk/pi/src/config/endpoint.rs index 19356db690c5..302031bb568b 100644 --- a/sdk/pi/src/config/endpoint.rs +++ b/sdk/pi/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -876,7 +835,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -895,7 +853,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -912,7 +869,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -932,7 +888,6 @@ mod test { /// Missing region #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -941,6 +896,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Performance Insights +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -977,27 +996,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pinpoint/src/config.rs b/sdk/pinpoint/src/config.rs index d056c08dc0aa..6aecf9e4788c 100644 --- a/sdk/pinpoint/src/config.rs +++ b/sdk/pinpoint/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpoint`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pinpoint::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pinpoint::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pinpoint::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pinpoint::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pinpoint::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpoint`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pinpoint/src/config/endpoint.rs b/sdk/pinpoint/src/config/endpoint.rs index 294a0047b0fe..dd0dcad3e607 100644 --- a/sdk/pinpoint/src/config/endpoint.rs +++ b/sdk/pinpoint/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -708,7 +675,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -727,7 +693,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -744,7 +709,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -764,7 +728,6 @@ mod test { /// Missing region #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -773,6 +736,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Pinpoint +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -809,27 +836,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pinpointemail/src/config.rs b/sdk/pinpointemail/src/config.rs index 5a66493f9050..b2ae35d80979 100644 --- a/sdk/pinpointemail/src/config.rs +++ b/sdk/pinpointemail/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpointemail`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pinpointemail::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pinpointemail::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pinpointemail::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pinpointemail::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pinpointemail::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpointemail`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pinpointemail/src/config/endpoint.rs b/sdk/pinpointemail/src/config/endpoint.rs index fad19bb87516..846a6dfa3039 100644 --- a/sdk/pinpointemail/src/config/endpoint.rs +++ b/sdk/pinpointemail/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Pinpoint Email Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pinpointsmsvoice/src/config.rs b/sdk/pinpointsmsvoice/src/config.rs index 704b3c426768..5c5f90219940 100644 --- a/sdk/pinpointsmsvoice/src/config.rs +++ b/sdk/pinpointsmsvoice/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpointsmsvoice`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pinpointsmsvoice::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pinpointsmsvoice::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pinpointsmsvoice::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pinpointsmsvoice::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pinpointsmsvoice::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpointsmsvoice`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pinpointsmsvoice/src/config/endpoint.rs b/sdk/pinpointsmsvoice/src/config/endpoint.rs index 3aad5adde10c..a299d74ed9ed 100644 --- a/sdk/pinpointsmsvoice/src/config/endpoint.rs +++ b/sdk/pinpointsmsvoice/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Pinpoint SMS and Voice Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pinpointsmsvoicev2/src/config.rs b/sdk/pinpointsmsvoicev2/src/config.rs index bfe91a812e03..6681c1ab90ee 100644 --- a/sdk/pinpointsmsvoicev2/src/config.rs +++ b/sdk/pinpointsmsvoicev2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpointsmsvoicev2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pinpointsmsvoicev2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pinpointsmsvoicev2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pinpointsmsvoicev2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pinpointsmsvoicev2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pinpointsmsvoicev2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pinpointsmsvoicev2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pinpointsmsvoicev2/src/config/endpoint.rs b/sdk/pinpointsmsvoicev2/src/config/endpoint.rs index dc13161d991f..52b4b7705be8 100644 --- a/sdk/pinpointsmsvoicev2/src/config/endpoint.rs +++ b/sdk/pinpointsmsvoicev2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Pinpoint SMS Voice V2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pipes/src/config.rs b/sdk/pipes/src/config.rs index c78149c04ea6..65defa0e9987 100644 --- a/sdk/pipes/src/config.rs +++ b/sdk/pipes/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pipes`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pipes::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pipes::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pipes::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pipes::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pipes::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pipes`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pipes/src/config/endpoint.rs b/sdk/pipes/src/config/endpoint.rs index df07a52849e9..e9517d3011e2 100644 --- a/sdk/pipes/src/config/endpoint.rs +++ b/sdk/pipes/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon EventBridge Pipes +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/polly/src/config.rs b/sdk/polly/src/config.rs index a87abfa9085b..d7389f61963c 100644 --- a/sdk/polly/src/config.rs +++ b/sdk/polly/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_polly`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_polly::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_polly::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_polly::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_polly::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_polly::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_polly`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/polly/src/config/endpoint.rs b/sdk/polly/src/config/endpoint.rs index 70b8c6613a02..3cfa9365fd6d 100644 --- a/sdk/polly/src/config/endpoint.rs +++ b/sdk/polly/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Polly +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/pricing/src/config.rs b/sdk/pricing/src/config.rs index 31450f5d3332..a6b6a31440f8 100644 --- a/sdk/pricing/src/config.rs +++ b/sdk/pricing/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pricing`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_pricing::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_pricing::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_pricing::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_pricing::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_pricing::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_pricing`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/pricing/src/config/endpoint.rs b/sdk/pricing/src/config/endpoint.rs index 54e8416b8aa5..1c297fa0d33b 100644 --- a/sdk/pricing/src/config/endpoint.rs +++ b/sdk/pricing/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -456,7 +435,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -475,7 +453,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +469,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -512,7 +488,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -521,6 +496,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Price List Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -557,27 +596,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/privatenetworks/src/config.rs b/sdk/privatenetworks/src/config.rs index c84213267b36..cfd7a7015c93 100644 --- a/sdk/privatenetworks/src/config.rs +++ b/sdk/privatenetworks/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_privatenetworks`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_privatenetworks::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_privatenetworks::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_privatenetworks::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_privatenetworks::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_privatenetworks::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_privatenetworks`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/privatenetworks/src/config/endpoint.rs b/sdk/privatenetworks/src/config/endpoint.rs index eb26a4019b83..e59173a8e87a 100644 --- a/sdk/privatenetworks/src/config/endpoint.rs +++ b/sdk/privatenetworks/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Private 5G +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/proton/src/config.rs b/sdk/proton/src/config.rs index ec6bf8683476..04eca150bb18 100644 --- a/sdk/proton/src/config.rs +++ b/sdk/proton/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_proton`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_proton::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_proton::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_proton::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_proton::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_proton::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_proton`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/proton/src/config/endpoint.rs b/sdk/proton/src/config/endpoint.rs index 08e86bd33e82..df86a5db5150 100644 --- a/sdk/proton/src/config/endpoint.rs +++ b/sdk/proton/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -364,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -401,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -441,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -478,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -519,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -538,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -575,7 +548,6 @@ mod test { /// Missing region #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -584,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Proton +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -620,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/qldb/src/config.rs b/sdk/qldb/src/config.rs index a04aa1d2effc..902f41246940 100644 --- a/sdk/qldb/src/config.rs +++ b/sdk/qldb/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_qldb`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_qldb::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_qldb::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_qldb::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_qldb::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_qldb::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_qldb`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/qldb/src/config/endpoint.rs b/sdk/qldb/src/config/endpoint.rs index 085e3b94a206..c5042fed96b1 100644 --- a/sdk/qldb/src/config/endpoint.rs +++ b/sdk/qldb/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -611,7 +583,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -651,7 +621,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -688,7 +656,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -708,7 +675,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -727,7 +693,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -744,7 +709,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -764,7 +728,6 @@ mod test { /// Missing region #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -773,6 +736,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon QLDB +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -809,27 +836,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/qldbsession/src/config.rs b/sdk/qldbsession/src/config.rs index 959caaa054a8..fc113d7e3eb8 100644 --- a/sdk/qldbsession/src/config.rs +++ b/sdk/qldbsession/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_qldbsession`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_qldbsession::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_qldbsession::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_qldbsession::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_qldbsession::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_qldbsession::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_qldbsession`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/qldbsession/src/config/endpoint.rs b/sdk/qldbsession/src/config/endpoint.rs index 6c33ab7be046..9db311fb736d 100644 --- a/sdk/qldbsession/src/config/endpoint.rs +++ b/sdk/qldbsession/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -532,7 +508,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -569,7 +543,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -687,7 +655,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -706,7 +673,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +689,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -743,7 +708,6 @@ mod test { /// Missing region #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -752,6 +716,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon QLDB Session +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -788,27 +816,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/quicksight/src/config.rs b/sdk/quicksight/src/config.rs index 135d26db9722..47c895c76dca 100644 --- a/sdk/quicksight/src/config.rs +++ b/sdk/quicksight/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_quicksight`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_quicksight::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_quicksight::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_quicksight::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_quicksight::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_quicksight::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_quicksight`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/quicksight/src/config/endpoint.rs b/sdk/quicksight/src/config/endpoint.rs index e6a27dee8c2d..2640cab9d221 100644 --- a/sdk/quicksight/src/config/endpoint.rs +++ b/sdk/quicksight/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region api with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("api".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region api with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("api".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon QuickSight +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ram/src/config.rs b/sdk/ram/src/config.rs index 67ba56ae2695..1e7ee62f8f8e 100644 --- a/sdk/ram/src/config.rs +++ b/sdk/ram/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ram`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ram::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ram::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ram::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ram::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ram::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ram`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ram/src/config/endpoint.rs b/sdk/ram/src/config/endpoint.rs index 8c7f51be3665..b3f355c8e5b9 100644 --- a/sdk/ram/src/config/endpoint.rs +++ b/sdk/ram/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Resource Access Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/rbin/src/config.rs b/sdk/rbin/src/config.rs index 5912e5a2b5bd..d89c52256a80 100644 --- a/sdk/rbin/src/config.rs +++ b/sdk/rbin/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rbin`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_rbin::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_rbin::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_rbin::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_rbin::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_rbin::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rbin`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/rbin/src/config/endpoint.rs b/sdk/rbin/src/config/endpoint.rs index 3756a009b4c7..a6dba86fb233 100644 --- a/sdk/rbin/src/config/endpoint.rs +++ b/sdk/rbin/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Recycle Bin +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/rds/src/config.rs b/sdk/rds/src/config.rs index a2c51356b4db..f0a83f2df15b 100644 --- a/sdk/rds/src/config.rs +++ b/sdk/rds/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rds`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_rds::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_rds::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_rds::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_rds::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_rds::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rds`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/rds/src/config/endpoint.rs b/sdk/rds/src/config/endpoint.rs index b7d06d90ca29..e12572a2dea3 100644 --- a/sdk/rds/src/config/endpoint.rs +++ b/sdk/rds/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -931,7 +888,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -968,7 +923,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1008,7 +961,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1024,7 +976,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1044,7 +995,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1063,7 +1013,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1080,7 +1029,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1100,7 +1048,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1109,6 +1056,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Relational Database Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1145,27 +1156,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/rdsdata/src/config.rs b/sdk/rdsdata/src/config.rs index aa30ade78128..0639893b9412 100644 --- a/sdk/rdsdata/src/config.rs +++ b/sdk/rdsdata/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rdsdata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_rdsdata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_rdsdata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_rdsdata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_rdsdata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_rdsdata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rdsdata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/rdsdata/src/config/endpoint.rs b/sdk/rdsdata/src/config/endpoint.rs index 77538f8d8a5a..6c582faf70dd 100644 --- a/sdk/rdsdata/src/config/endpoint.rs +++ b/sdk/rdsdata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS RDS DataService +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/redshift/src/config.rs b/sdk/redshift/src/config.rs index bac8e0bacb71..712179aede72 100644 --- a/sdk/redshift/src/config.rs +++ b/sdk/redshift/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_redshift`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_redshift::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_redshift::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_redshift::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_redshift::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_redshift::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_redshift`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/redshift/src/config/endpoint.rs b/sdk/redshift/src/config/endpoint.rs index 3bc2fb51193a..937dd863cfd7 100644 --- a/sdk/redshift/src/config/endpoint.rs +++ b/sdk/redshift/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -891,7 +850,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -931,7 +888,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -968,7 +923,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1008,7 +961,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1024,7 +976,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1044,7 +995,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1063,7 +1013,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1080,7 +1029,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1100,7 +1048,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1109,6 +1056,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Redshift +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1145,27 +1156,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/redshiftdata/src/config.rs b/sdk/redshiftdata/src/config.rs index e349d637e9fe..50835a1935f8 100644 --- a/sdk/redshiftdata/src/config.rs +++ b/sdk/redshiftdata/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_redshiftdata`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_redshiftdata::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_redshiftdata::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_redshiftdata::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_redshiftdata::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_redshiftdata::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_redshiftdata`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/redshiftdata/src/config/endpoint.rs b/sdk/redshiftdata/src/config/endpoint.rs index c528daaeefaf..9fbba1d1a947 100644 --- a/sdk/redshiftdata/src/config/endpoint.rs +++ b/sdk/redshiftdata/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Redshift Data API Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/redshiftserverless/src/config.rs b/sdk/redshiftserverless/src/config.rs index 85aea7309ecf..0ea88addfed5 100644 --- a/sdk/redshiftserverless/src/config.rs +++ b/sdk/redshiftserverless/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_redshiftserverless`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_redshiftserverless::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_redshiftserverless::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_redshiftserverless::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_redshiftserverless::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_redshiftserverless::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_redshiftserverless`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/redshiftserverless/src/config/endpoint.rs b/sdk/redshiftserverless/src/config/endpoint.rs index ef6266ffdcfb..8562f279cb96 100644 --- a/sdk/redshiftserverless/src/config/endpoint.rs +++ b/sdk/redshiftserverless/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -511,7 +488,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -548,7 +523,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -588,7 +561,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -625,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -645,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -664,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -681,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -701,7 +668,6 @@ mod test { /// Missing region #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -710,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to Redshift Serverless +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -746,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/rekognition/src/config.rs b/sdk/rekognition/src/config.rs index f2e7c69d5d4c..e4ddeb386c4b 100644 --- a/sdk/rekognition/src/config.rs +++ b/sdk/rekognition/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rekognition`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_rekognition::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_rekognition::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_rekognition::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_rekognition::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_rekognition::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rekognition`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/rekognition/src/config/endpoint.rs b/sdk/rekognition/src/config/endpoint.rs index 5e75076fafe0..d7ef7c27bb08 100644 --- a/sdk/rekognition/src/config/endpoint.rs +++ b/sdk/rekognition/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -658,7 +628,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -695,7 +663,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -735,7 +701,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -772,7 +736,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -813,7 +775,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -832,7 +793,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -849,7 +809,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -869,7 +828,6 @@ mod test { /// Missing region #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -878,6 +836,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Rekognition +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -914,27 +936,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/resiliencehub/src/config.rs b/sdk/resiliencehub/src/config.rs index d8911e210d02..18b3f89ff268 100644 --- a/sdk/resiliencehub/src/config.rs +++ b/sdk/resiliencehub/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resiliencehub`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_resiliencehub::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_resiliencehub::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_resiliencehub::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_resiliencehub::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_resiliencehub::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resiliencehub`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/resiliencehub/src/config/endpoint.rs b/sdk/resiliencehub/src/config/endpoint.rs index 5222165ee68f..2d81e5775031 100644 --- a/sdk/resiliencehub/src/config/endpoint.rs +++ b/sdk/resiliencehub/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -834,7 +795,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -853,7 +813,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -870,7 +829,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -890,7 +848,6 @@ mod test { /// Missing region #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -899,6 +856,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Resilience Hub +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -935,27 +956,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/resourceexplorer2/src/config.rs b/sdk/resourceexplorer2/src/config.rs index bcd41df734e6..546b253bdcb9 100644 --- a/sdk/resourceexplorer2/src/config.rs +++ b/sdk/resourceexplorer2/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resourceexplorer2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_resourceexplorer2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_resourceexplorer2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_resourceexplorer2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_resourceexplorer2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_resourceexplorer2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resourceexplorer2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -957,11 +940,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1152,7 +1134,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/resourceexplorer2/src/config/endpoint.rs b/sdk/resourceexplorer2/src/config/endpoint.rs index 0f67a25e55a2..24210da9dabb 100644 --- a/sdk/resourceexplorer2/src/config/endpoint.rs +++ b/sdk/resourceexplorer2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -29,7 +29,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -49,7 +48,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -69,7 +67,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -89,7 +86,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -109,7 +105,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -129,7 +124,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -148,7 +142,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .endpoint("https://example.com".to_string()) @@ -166,7 +159,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -182,7 +174,6 @@ mod test { /// Missing region #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -191,6 +182,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Resource Explorer +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -221,27 +276,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/resourcegroups/src/config.rs b/sdk/resourcegroups/src/config.rs index 980509d5866b..37131acf2453 100644 --- a/sdk/resourcegroups/src/config.rs +++ b/sdk/resourcegroups/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resourcegroups`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_resourcegroups::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_resourcegroups::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_resourcegroups::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_resourcegroups::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_resourcegroups::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resourcegroups`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/resourcegroups/src/config/endpoint.rs b/sdk/resourcegroups/src/config/endpoint.rs index 056249cd3614..48b6c87258ec 100644 --- a/sdk/resourcegroups/src/config/endpoint.rs +++ b/sdk/resourcegroups/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Resource Groups +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/resourcegroupstagging/src/config.rs b/sdk/resourcegroupstagging/src/config.rs index e0d01fccf33b..c8b5e8ad6aa6 100644 --- a/sdk/resourcegroupstagging/src/config.rs +++ b/sdk/resourcegroupstagging/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resourcegroupstagging`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_resourcegroupstagging::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_resourcegroupstagging::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_resourcegroupstagging::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_resourcegroupstagging::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_resourcegroupstagging::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_resourcegroupstagging`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/resourcegroupstagging/src/config/endpoint.rs b/sdk/resourcegroupstagging/src/config/endpoint.rs index f5f4720f16a1..64b99bd1656e 100644 --- a/sdk/resourcegroupstagging/src/config/endpoint.rs +++ b/sdk/resourcegroupstagging/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -918,7 +875,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -937,7 +893,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +909,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -974,7 +928,6 @@ mod test { /// Missing region #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -983,6 +936,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Resource Groups Tagging API +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1019,27 +1036,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/robomaker/src/config.rs b/sdk/robomaker/src/config.rs index 7d85c26c1601..cb199f71c42b 100644 --- a/sdk/robomaker/src/config.rs +++ b/sdk/robomaker/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_robomaker`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_robomaker::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_robomaker::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_robomaker::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_robomaker::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_robomaker::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_robomaker`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/robomaker/src/config/endpoint.rs b/sdk/robomaker/src/config/endpoint.rs index 8e999fc2c9f0..bb4337433878 100644 --- a/sdk/robomaker/src/config/endpoint.rs +++ b/sdk/robomaker/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -448,7 +428,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -485,7 +463,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -525,7 +501,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -562,7 +536,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -582,7 +555,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -601,7 +573,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -618,7 +589,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -638,7 +608,6 @@ mod test { /// Missing region #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -647,6 +616,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS RoboMaker +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -683,27 +716,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/rolesanywhere/src/config.rs b/sdk/rolesanywhere/src/config.rs index 14989a5fe3a4..c13dc90b55b7 100644 --- a/sdk/rolesanywhere/src/config.rs +++ b/sdk/rolesanywhere/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rolesanywhere`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_rolesanywhere::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_rolesanywhere::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_rolesanywhere::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_rolesanywhere::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_rolesanywhere::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rolesanywhere`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/rolesanywhere/src/config/endpoint.rs b/sdk/rolesanywhere/src/config/endpoint.rs index 1f9479799d15..3d949c1b549a 100644 --- a/sdk/rolesanywhere/src/config/endpoint.rs +++ b/sdk/rolesanywhere/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -658,7 +628,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -695,7 +663,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -735,7 +701,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -772,7 +736,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -813,7 +775,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -832,7 +793,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -849,7 +809,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -869,7 +828,6 @@ mod test { /// Missing region #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -878,6 +836,70 @@ mod test { } } +/// Endpoint resolver trait specific to IAM Roles Anywhere +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -914,27 +936,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/route53/src/config.rs b/sdk/route53/src/config.rs index 2fe4c9005657..77df73398e63 100644 --- a/sdk/route53/src/config.rs +++ b/sdk/route53/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_route53::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_route53::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_route53::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_route53::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_route53::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/route53/src/config/endpoint.rs b/sdk/route53/src/config/endpoint.rs index 6dfa1ba844a0..948e10ad1376 100644 --- a/sdk/route53/src/config/endpoint.rs +++ b/sdk/route53/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region aws-global with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -71,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -92,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -123,7 +120,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -144,7 +140,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -175,7 +170,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -206,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -227,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -248,7 +240,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -269,7 +260,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -300,7 +290,6 @@ mod test { /// For region aws-us-gov-global with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(false) @@ -331,7 +320,6 @@ mod test { /// For region aws-us-gov-global with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(true) @@ -362,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -383,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -414,7 +400,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -435,7 +420,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -466,7 +450,6 @@ mod test { /// For region aws-iso-global with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-iso-global".to_string()) .use_fips(false) @@ -497,7 +480,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -516,7 +498,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -537,7 +518,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -553,7 +533,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -584,7 +563,6 @@ mod test { /// For region aws-iso-b-global with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-iso-b-global".to_string()) .use_fips(false) @@ -615,7 +593,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -634,7 +611,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -655,7 +631,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -671,7 +646,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -702,7 +676,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -722,7 +695,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -741,7 +713,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -758,7 +729,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -778,7 +748,6 @@ mod test { /// Missing region #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -787,6 +756,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Route 53 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -823,27 +856,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/route53/src/operation/get_change.rs b/sdk/route53/src/operation/get_change.rs index 3d0b9ff5b586..6470a0f8df48 100644 --- a/sdk/route53/src/operation/get_change.rs +++ b/sdk/route53/src/operation/get_change.rs @@ -252,9 +252,7 @@ mod get_change_request_test { #[allow(unused_mut)] async fn get_change_trim_change_id_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/route53/src/operation/get_reusable_delegation_set.rs b/sdk/route53/src/operation/get_reusable_delegation_set.rs index 447b8ef645b2..3b4273c20052 100644 --- a/sdk/route53/src/operation/get_reusable_delegation_set.rs +++ b/sdk/route53/src/operation/get_reusable_delegation_set.rs @@ -255,9 +255,7 @@ mod get_reusable_delegation_set_request_test { #[allow(unused_mut)] async fn get_reusable_delegation_set_trim_delegation_set_id_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/route53/src/operation/list_resource_record_sets.rs b/sdk/route53/src/operation/list_resource_record_sets.rs index 8fe13a27a76c..663646183051 100644 --- a/sdk/route53/src/operation/list_resource_record_sets.rs +++ b/sdk/route53/src/operation/list_resource_record_sets.rs @@ -284,9 +284,7 @@ mod list_resource_record_sets_request_test { #[allow(unused_mut)] async fn list_resource_record_sets_trim_hosted_zone_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/route53domains/src/config.rs b/sdk/route53domains/src/config.rs index 16e143c4c7b9..fa2e008d8a95 100644 --- a/sdk/route53domains/src/config.rs +++ b/sdk/route53domains/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53domains`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_route53domains::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_route53domains::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_route53domains::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_route53domains::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_route53domains::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53domains`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/route53domains/src/config/endpoint.rs b/sdk/route53domains/src/config/endpoint.rs index 9cb8dfb40781..cec0d45d13d6 100644 --- a/sdk/route53domains/src/config/endpoint.rs +++ b/sdk/route53domains/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Route 53 Domains +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/route53recoverycluster/src/config.rs b/sdk/route53recoverycluster/src/config.rs index 332e6ca9cd8c..43097cea8640 100644 --- a/sdk/route53recoverycluster/src/config.rs +++ b/sdk/route53recoverycluster/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53recoverycluster`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_route53recoverycluster::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_route53recoverycluster::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_route53recoverycluster::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_route53recoverycluster::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_route53recoverycluster::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53recoverycluster`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/route53recoverycluster/src/config/endpoint.rs b/sdk/route53recoverycluster/src/config/endpoint.rs index 0f1952e0fad9..0bae68d47aef 100644 --- a/sdk/route53recoverycluster/src/config/endpoint.rs +++ b/sdk/route53recoverycluster/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Route53 Recovery Cluster +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/route53recoverycontrolconfig/src/config.rs b/sdk/route53recoverycontrolconfig/src/config.rs index be6ff9c2b573..e20badea65e8 100644 --- a/sdk/route53recoverycontrolconfig/src/config.rs +++ b/sdk/route53recoverycontrolconfig/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53recoverycontrolconfig`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_route53recoverycontrolconfig::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_route53recoverycontrolconfig::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_route53recoverycontrolconfig::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_route53recoverycontrolconfig::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_route53recoverycontrolconfig::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53recoverycontrolconfig`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/route53recoverycontrolconfig/src/config/endpoint.rs b/sdk/route53recoverycontrolconfig/src/config/endpoint.rs index 19bfa7ddffb5..ab397b0725f5 100644 --- a/sdk/route53recoverycontrolconfig/src/config/endpoint.rs +++ b/sdk/route53recoverycontrolconfig/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -124,7 +120,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -146,7 +141,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -167,7 +161,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -188,7 +181,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -209,7 +201,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -230,7 +221,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -251,7 +241,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -272,7 +261,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -293,7 +281,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -312,7 +299,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -333,7 +319,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -349,7 +334,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -370,7 +354,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -389,7 +372,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -410,7 +392,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -426,7 +407,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -447,7 +427,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -467,7 +446,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -486,7 +464,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -503,7 +480,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -523,7 +499,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -532,6 +507,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Route53 Recovery Control Config +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -568,27 +607,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/route53recoveryreadiness/src/config.rs b/sdk/route53recoveryreadiness/src/config.rs index b6ef571268cf..3c78f1d62e74 100644 --- a/sdk/route53recoveryreadiness/src/config.rs +++ b/sdk/route53recoveryreadiness/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53recoveryreadiness`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_route53recoveryreadiness::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_route53recoveryreadiness::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_route53recoveryreadiness::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_route53recoveryreadiness::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_route53recoveryreadiness::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53recoveryreadiness`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/route53recoveryreadiness/src/config/endpoint.rs b/sdk/route53recoveryreadiness/src/config/endpoint.rs index 9ca738120097..d20e5259a5c1 100644 --- a/sdk/route53recoveryreadiness/src/config/endpoint.rs +++ b/sdk/route53recoveryreadiness/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Route53 Recovery Readiness +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/route53resolver/src/config.rs b/sdk/route53resolver/src/config.rs index c16fa9643926..f3c2e43a1241 100644 --- a/sdk/route53resolver/src/config.rs +++ b/sdk/route53resolver/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53resolver`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_route53resolver::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_route53resolver::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_route53resolver::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_route53resolver::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_route53resolver::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_route53resolver`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/route53resolver/src/config/endpoint.rs b/sdk/route53resolver/src/config/endpoint.rs index 265d074da0e6..158f9d4455c5 100644 --- a/sdk/route53resolver/src/config/endpoint.rs +++ b/sdk/route53resolver/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -939,7 +895,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -958,7 +913,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -975,7 +929,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -995,7 +948,6 @@ mod test { /// Missing region #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1004,6 +956,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Route 53 Resolver +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1040,27 +1056,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/rum/src/config.rs b/sdk/rum/src/config.rs index 389fb5fb8716..1f9eac228f1f 100644 --- a/sdk/rum/src/config.rs +++ b/sdk/rum/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rum`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_rum::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_rum::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_rum::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_rum::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_rum::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_rum`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/rum/src/config/endpoint.rs b/sdk/rum/src/config/endpoint.rs index 5c4bae3a4f34..43092572c5b9 100644 --- a/sdk/rum/src/config/endpoint.rs +++ b/sdk/rum/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -469,7 +448,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -490,7 +468,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -506,7 +483,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -527,7 +503,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -546,7 +521,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -567,7 +541,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -583,7 +556,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -604,7 +576,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -624,7 +595,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -643,7 +613,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -660,7 +629,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -680,7 +648,6 @@ mod test { /// Missing region #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -689,6 +656,70 @@ mod test { } } +/// Endpoint resolver trait specific to CloudWatch RUM +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -725,27 +756,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/s3/src/config.rs b/sdk/s3/src/config.rs index b809991a6a3a..297e507a4f70 100644 --- a/sdk/s3/src/config.rs +++ b/sdk/s3/src/config.rs @@ -271,63 +271,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_s3`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_s3::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_s3::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_s3::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_s3::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_s3::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_s3`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -993,11 +976,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1223,7 +1205,7 @@ impl ::aws_smithy_types::config_bag::Storable for Accelerate { /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/s3/src/config/endpoint.rs b/sdk/s3/src/config/endpoint.rs index b5c7fb94ed17..674589a963bc 100644 --- a/sdk/s3/src/config/endpoint.rs +++ b/sdk/s3/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// region is not a valid DNS-suffix #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("a b".to_string()) .use_fips(false) @@ -26,7 +26,6 @@ mod test { /// Invalid access point ARN: Not S3 #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -45,7 +44,6 @@ mod test { /// Invalid access point ARN: invalid resource #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -66,7 +64,6 @@ mod test { /// Invalid access point ARN: invalid no ap name #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -87,7 +84,6 @@ mod test { /// Invalid access point ARN: AccountId is invalid #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -108,7 +104,6 @@ mod test { /// Invalid access point ARN: access point name is invalid #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -129,7 +124,6 @@ mod test { /// Access points (disable access points explicitly false) #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -164,7 +158,6 @@ mod test { /// Access points: partition does not support FIPS #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -182,7 +175,6 @@ mod test { /// Bucket region is invalid #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -201,7 +193,6 @@ mod test { /// Access points when Access points explicitly disabled (used for CreateBucket) #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -220,7 +211,6 @@ mod test { /// missing arn type #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -242,7 +232,6 @@ mod test { /// SDK::Host + access point + Dualstack is an error #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint".to_string()) @@ -264,7 +253,6 @@ mod test { /// Access point ARN with FIPS & Dualstack #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -300,7 +288,6 @@ mod test { /// Access point ARN with Dualstack #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -335,7 +322,6 @@ mod test { /// vanilla MRAP #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3::123456789012:accesspoint:mfzwi23gnjvgw.mrap".to_string()) .region("us-east-1".to_string()) @@ -373,7 +359,6 @@ mod test { /// MRAP does not support FIPS #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3::123456789012:accesspoint:mfzwi23gnjvgw.mrap".to_string()) .region("us-east-1".to_string()) @@ -392,7 +377,6 @@ mod test { /// MRAP does not support DualStack #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3::123456789012:accesspoint:mfzwi23gnjvgw.mrap".to_string()) .region("us-east-1".to_string()) @@ -411,7 +395,6 @@ mod test { /// MRAP does not support S3 Accelerate #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3::123456789012:accesspoint:mfzwi23gnjvgw.mrap".to_string()) .region("us-east-1".to_string()) @@ -430,7 +413,6 @@ mod test { /// MRAP explicitly disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3::123456789012:accesspoint:mfzwi23gnjvgw.mrap".to_string()) .region("us-east-1".to_string()) @@ -453,7 +435,6 @@ mod test { /// Dual-stack endpoint with path-style forced #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucketname".to_string()) .region("us-west-2".to_string()) @@ -488,7 +469,6 @@ mod test { /// Dual-stack endpoint + SDK::Host is error #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucketname".to_string()) .region("us-west-2".to_string()) @@ -509,7 +489,6 @@ mod test { /// path style + ARN bucket #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3::123456789012:accesspoint:mfzwi23gnjvgw.mrap".to_string()) @@ -528,7 +507,6 @@ mod test { /// implicit path style bucket + dualstack #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99_ab".to_string()) @@ -562,7 +540,6 @@ mod test { /// implicit path style bucket + dualstack #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99_ab".to_string()) @@ -582,7 +559,6 @@ mod test { /// don't allow URL injections in the bucket #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("example.com#".to_string()) .region("us-west-2".to_string()) @@ -616,7 +592,6 @@ mod test { /// URI encode bucket names in the path #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucket name".to_string()) .region("us-west-2".to_string()) @@ -650,7 +625,6 @@ mod test { /// scheme is respected #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99_ab".to_string()) @@ -685,7 +659,6 @@ mod test { /// scheme is respected (virtual addressing) #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucketname".to_string()) @@ -720,7 +693,6 @@ mod test { /// path style + implicit private link #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99_ab".to_string()) @@ -755,7 +727,6 @@ mod test { /// invalid Endpoint override #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucketname".to_string()) @@ -774,7 +745,6 @@ mod test { /// using an IPv4 address forces path style #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucketname".to_string()) @@ -809,7 +779,6 @@ mod test { /// vanilla access point arn with region mismatch and UseArnRegion=false #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint".to_string()) @@ -832,7 +801,6 @@ mod test { /// vanilla access point arn with region mismatch and UseArnRegion unset #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -867,7 +835,6 @@ mod test { /// vanilla access point arn with region mismatch and UseArnRegion=true #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -903,7 +870,6 @@ mod test { /// subdomains are not allowed in virtual buckets #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucket.name".to_string()) .region("us-east-1".to_string()) @@ -934,7 +900,6 @@ mod test { /// bucket names with 3 characters are allowed in virtual buckets #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("aaa".to_string()) .region("us-east-1".to_string()) @@ -965,7 +930,6 @@ mod test { /// bucket names with fewer than 3 characters are not allowed in virtual host #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("aa".to_string()) .region("us-east-1".to_string()) @@ -996,7 +960,6 @@ mod test { /// bucket names with uppercase characters are not allowed in virtual host #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("BucketName".to_string()) .region("us-east-1".to_string()) @@ -1027,7 +990,6 @@ mod test { /// subdomains are allowed in virtual buckets on http endpoints #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucket.name".to_string()) .region("us-east-1".to_string()) @@ -1059,7 +1021,6 @@ mod test { /// no region set #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucket-name".to_string()) .build() @@ -1073,7 +1034,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-east-1 uses the global endpoint #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1107,7 +1067,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-west-2 uses the regional endpoint #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_global_endpoint(true) @@ -1141,7 +1100,6 @@ mod test { /// UseGlobalEndpoints=true, region=cn-north-1 uses the regional endpoint #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_global_endpoint(true) @@ -1175,7 +1133,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-east-1, fips=true uses the regional endpoint with fips #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1209,7 +1166,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-east-1, dualstack=true uses the regional endpoint with dualstack #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1243,7 +1199,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-east-1, dualstack and fips uses the regional endpoint with fips/dualstack #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1277,7 +1232,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-east-1 with custom endpoint, uses custom #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .endpoint("https://example.com".to_string()) @@ -1312,7 +1266,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-west-2 with custom endpoint, uses custom #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .endpoint("https://example.com".to_string()) @@ -1347,7 +1300,6 @@ mod test { /// UseGlobalEndpoints=true, region=us-east-1 with accelerate on non bucket case uses the global endpoint and ignores accelerate #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1381,7 +1333,6 @@ mod test { /// aws-global region uses the global endpoint #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -1414,7 +1365,6 @@ mod test { /// aws-global region with fips uses the regional endpoint #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -1447,7 +1397,6 @@ mod test { /// aws-global region with dualstack uses the regional endpoint #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -1480,7 +1429,6 @@ mod test { /// aws-global region with fips and dualstack uses the regional endpoint #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -1513,7 +1461,6 @@ mod test { /// aws-global region with accelerate on non-bucket case, uses global endpoint and ignores accelerate #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -1546,7 +1493,6 @@ mod test { /// aws-global region with custom endpoint, uses custom #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .endpoint("https://example.com".to_string()) @@ -1581,7 +1527,6 @@ mod test { /// virtual addressing, aws-global region uses the global endpoint #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -1615,7 +1560,6 @@ mod test { /// virtual addressing, aws-global region with fips uses the regional fips endpoint #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -1649,7 +1593,6 @@ mod test { /// virtual addressing, aws-global region with dualstack uses the regional dualstack endpoint #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -1683,7 +1626,6 @@ mod test { /// virtual addressing, aws-global region with fips/dualstack uses the regional fips/dualstack endpoint #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -1717,7 +1659,6 @@ mod test { /// virtual addressing, aws-global region with accelerate uses the global accelerate endpoint #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -1751,7 +1692,6 @@ mod test { /// virtual addressing, aws-global region with custom endpoint #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .endpoint("https://example.com".to_string()) @@ -1786,7 +1726,6 @@ mod test { /// virtual addressing, UseGlobalEndpoint and us-east-1 region uses the global endpoint #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1821,7 +1760,6 @@ mod test { /// virtual addressing, UseGlobalEndpoint and us-west-2 region uses the regional endpoint #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_global_endpoint(true) @@ -1856,7 +1794,6 @@ mod test { /// virtual addressing, UseGlobalEndpoint and us-east-1 region and fips uses the regional fips endpoint #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1891,7 +1828,6 @@ mod test { /// virtual addressing, UseGlobalEndpoint and us-east-1 region and dualstack uses the regional dualstack endpoint #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1926,7 +1862,6 @@ mod test { /// virtual addressing, UseGlobalEndpoint and us-east-1 region and accelerate uses the global accelerate endpoint #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -1961,7 +1896,6 @@ mod test { /// virtual addressing, UseGlobalEndpoint and us-east-1 region with custom endpoint #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .endpoint("https://example.com".to_string()) @@ -1997,7 +1931,6 @@ mod test { /// ForcePathStyle, aws-global region uses the global endpoint #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -2032,7 +1965,6 @@ mod test { /// ForcePathStyle, aws-global region with fips is invalid #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -2067,7 +1999,6 @@ mod test { /// ForcePathStyle, aws-global region with dualstack uses regional dualstack endpoint #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket-name".to_string()) @@ -2102,7 +2033,6 @@ mod test { /// ForcePathStyle, aws-global region custom endpoint uses the custom endpoint #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .endpoint("https://example.com".to_string()) @@ -2138,7 +2068,6 @@ mod test { /// ForcePathStyle, UseGlobalEndpoint us-east-1 region uses the global endpoint #[test] fn test_72() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket-name".to_string()) @@ -2174,7 +2103,6 @@ mod test { /// ForcePathStyle, UseGlobalEndpoint us-west-2 region uses the regional endpoint #[test] fn test_73() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .bucket("bucket-name".to_string()) @@ -2210,7 +2138,6 @@ mod test { /// ForcePathStyle, UseGlobalEndpoint us-east-1 region, dualstack uses the regional dualstack endpoint #[test] fn test_74() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket-name".to_string()) @@ -2246,7 +2173,6 @@ mod test { /// ForcePathStyle, UseGlobalEndpoint us-east-1 region custom endpoint uses the custom endpoint #[test] fn test_75() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket-name".to_string()) @@ -2283,7 +2209,6 @@ mod test { /// ARN with aws-global region and UseArnRegion uses the regional endpoint #[test] fn test_76() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_arn_region(true) @@ -2319,7 +2244,6 @@ mod test { /// cross partition MRAP ARN is an error #[test] fn test_77() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-cn:s3::123456789012:accesspoint:mfzwi23gnjvgw.mrap".to_string()) .region("us-west-1".to_string()) @@ -2337,7 +2261,6 @@ mod test { /// Endpoint override, accesspoint with HTTP, port #[test] fn test_78() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .endpoint("http://beta.example.com:1234".to_string()) .region("us-west-2".to_string()) @@ -2369,7 +2292,6 @@ mod test { /// Endpoint override, accesspoint with http, path, query, and port #[test] fn test_79() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -2404,7 +2326,6 @@ mod test { /// non-bucket endpoint override with FIPS = error #[test] fn test_80() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .endpoint("http://beta.example.com:1234/path".to_string()) @@ -2422,7 +2343,6 @@ mod test { /// FIPS + dualstack + custom endpoint #[test] fn test_81() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .endpoint("http://beta.example.com:1234/path".to_string()) @@ -2440,7 +2360,6 @@ mod test { /// dualstack + custom endpoint #[test] fn test_82() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .endpoint("http://beta.example.com:1234/path".to_string()) @@ -2457,7 +2376,6 @@ mod test { /// custom endpoint without FIPS/dualstack #[test] fn test_83() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .endpoint("http://beta.example.com:1234/path".to_string()) @@ -2490,7 +2408,6 @@ mod test { /// s3 object lambda with access points disabled #[test] fn test_84() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .bucket("arn:aws:s3-object-lambda:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -2507,7 +2424,6 @@ mod test { /// non bucket + FIPS #[test] fn test_85() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -2539,7 +2455,6 @@ mod test { /// standard non bucket endpoint #[test] fn test_86() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -2571,7 +2486,6 @@ mod test { /// non bucket endpoint with FIPS + Dualstack #[test] fn test_87() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -2603,7 +2517,6 @@ mod test { /// non bucket endpoint with dualstack #[test] fn test_88() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -2635,7 +2548,6 @@ mod test { /// use global endpoint + IP address endpoint override #[test] fn test_89() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket".to_string()) @@ -2670,7 +2582,6 @@ mod test { /// non-dns endpoint + global endpoint #[test] fn test_90() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2704,7 +2615,6 @@ mod test { /// endpoint override + use global endpoint #[test] fn test_91() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2739,7 +2649,6 @@ mod test { /// FIPS + dualstack + non-bucket endpoint #[test] fn test_92() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2772,7 +2681,6 @@ mod test { /// FIPS + dualstack + non-DNS endpoint #[test] fn test_93() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2806,7 +2714,6 @@ mod test { /// endpoint override + FIPS + dualstack (BUG) #[test] fn test_94() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2826,7 +2733,6 @@ mod test { /// endpoint override + non-dns bucket + FIPS (BUG) #[test] fn test_95() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2845,7 +2751,6 @@ mod test { /// FIPS + bucket endpoint + force path style #[test] fn test_96() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2880,7 +2785,6 @@ mod test { /// bucket + FIPS + force path style #[test] fn test_97() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket".to_string()) @@ -2915,7 +2819,6 @@ mod test { /// FIPS + dualstack + use global endpoint #[test] fn test_98() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket".to_string()) @@ -2949,7 +2852,6 @@ mod test { /// URI encoded bucket + use global endpoint #[test] fn test_99() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -2968,7 +2870,6 @@ mod test { /// FIPS + path based endpoint #[test] fn test_100() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -3003,7 +2904,6 @@ mod test { /// accelerate + dualstack + global endpoint #[test] fn test_101() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket".to_string()) @@ -3038,7 +2938,6 @@ mod test { /// dualstack + global endpoint + non URI safe bucket #[test] fn test_102() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -3073,7 +2972,6 @@ mod test { /// FIPS + uri encoded bucket #[test] fn test_103() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -3109,7 +3007,6 @@ mod test { /// endpoint override + non-uri safe endpoint + force path style #[test] fn test_104() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -3132,7 +3029,6 @@ mod test { /// FIPS + Dualstack + global endpoint + non-dns bucket #[test] fn test_105() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("bucket!".to_string()) @@ -3167,7 +3063,6 @@ mod test { /// endpoint override + FIPS + dualstack #[test] fn test_106() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_dual_stack(true) @@ -3186,7 +3081,6 @@ mod test { /// non-bucket endpoint override + dualstack + global endpoint #[test] fn test_107() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -3204,7 +3098,6 @@ mod test { /// Endpoint override + UseGlobalEndpoint + us-east-1 #[test] fn test_108() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -3223,7 +3116,6 @@ mod test { /// non-FIPS partition with FIPS set + custom endpoint #[test] fn test_109() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -3240,7 +3132,6 @@ mod test { /// aws-global signs as us-east-1 #[test] fn test_110() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3274,7 +3165,6 @@ mod test { /// aws-global signs as us-east-1 #[test] fn test_111() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket".to_string()) @@ -3309,7 +3199,6 @@ mod test { /// aws-global + dualstack + path-only bucket #[test] fn test_112() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3343,7 +3232,6 @@ mod test { /// aws-global + path-only bucket #[test] fn test_113() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3374,7 +3262,6 @@ mod test { /// aws-global + fips + custom endpoint #[test] fn test_114() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3393,7 +3280,6 @@ mod test { /// aws-global, endpoint override & path only-bucket #[test] fn test_115() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3428,7 +3314,6 @@ mod test { /// aws-global + dualstack + custom endpoint #[test] fn test_116() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_dual_stack(true) @@ -3447,7 +3332,6 @@ mod test { /// accelerate, dualstack + aws-global #[test] fn test_117() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket".to_string()) @@ -3481,7 +3365,6 @@ mod test { /// FIPS + aws-global + path only bucket. This is not supported by S3 but we allow garbage in garbage out #[test] fn test_118() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3516,7 +3399,6 @@ mod test { /// aws-global + FIPS + endpoint override. #[test] fn test_119() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -3532,7 +3414,6 @@ mod test { /// force path style, FIPS, aws-global & endpoint override #[test] fn test_120() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3551,7 +3432,6 @@ mod test { /// ip address causes path style to be forced #[test] fn test_121() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket".to_string()) @@ -3583,7 +3463,6 @@ mod test { /// endpoint override with aws-global region #[test] fn test_122() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -3601,7 +3480,6 @@ mod test { /// FIPS + path-only (TODO: consider making this an error) #[test] fn test_123() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .bucket("bucket!".to_string()) @@ -3633,7 +3511,6 @@ mod test { /// empty arn type #[test] fn test_124() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:not-s3:us-west-2:123456789012::myendpoint".to_string()) @@ -3648,7 +3525,6 @@ mod test { /// path style can't be used with accelerate #[test] fn test_125() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("bucket!".to_string()) @@ -3665,7 +3541,6 @@ mod test { /// invalid region #[test] fn test_126() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2!".to_string()) .bucket("bucket.subdomain".to_string()) @@ -3681,7 +3556,6 @@ mod test { /// invalid region #[test] fn test_127() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2!".to_string()) .bucket("bucket".to_string()) @@ -3697,7 +3571,6 @@ mod test { /// empty arn type #[test] fn test_128() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3::123456789012:accesspoint:my_endpoint".to_string()) @@ -3712,7 +3585,6 @@ mod test { /// empty arn type #[test] fn test_129() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3:cn-north-1:123456789012:accesspoint:my-endpoint".to_string()) @@ -3731,7 +3603,6 @@ mod test { /// invalid arn region #[test] fn test_130() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-object-lambda:us-east_2:123456789012:accesspoint:my-endpoint".to_string()) @@ -3747,7 +3618,6 @@ mod test { /// invalid ARN outpost #[test] fn test_131() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost/op_01234567890123456/accesspoint/reports".to_string()) @@ -3768,7 +3638,6 @@ mod test { /// invalid ARN #[test] fn test_132() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost/op-01234567890123456/reports".to_string()) @@ -3783,7 +3652,6 @@ mod test { /// invalid ARN #[test] fn test_133() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost/op-01234567890123456".to_string()) @@ -3798,7 +3666,6 @@ mod test { /// invalid outpost type #[test] fn test_134() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost/op-01234567890123456/not-accesspoint/reports".to_string()) @@ -3813,7 +3680,6 @@ mod test { /// invalid outpost type #[test] fn test_135() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-outposts:us-east_1:123456789012:outpost/op-01234567890123456/not-accesspoint/reports".to_string()) @@ -3828,7 +3694,6 @@ mod test { /// invalid outpost type #[test] fn test_136() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-outposts:us-east-1:12345_789012:outpost/op-01234567890123456/not-accesspoint/reports".to_string()) @@ -3848,7 +3713,6 @@ mod test { /// invalid outpost type #[test] fn test_137() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("arn:aws:s3-outposts:us-east-1:12345789012:outpost".to_string()) @@ -3863,7 +3727,6 @@ mod test { /// use global endpoint virtual addressing #[test] fn test_138() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("bucket".to_string()) @@ -3896,7 +3759,6 @@ mod test { /// global endpoint + ip address #[test] fn test_139() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("bucket".to_string()) @@ -3929,7 +3791,6 @@ mod test { /// invalid outpost type #[test] fn test_140() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("bucket!".to_string()) @@ -3961,7 +3822,6 @@ mod test { /// invalid outpost type #[test] fn test_141() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("bucket".to_string()) @@ -3994,7 +3854,6 @@ mod test { /// use global endpoint + custom endpoint #[test] fn test_142() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("bucket!".to_string()) @@ -4027,7 +3886,6 @@ mod test { /// use global endpoint, not us-east-1, force path style #[test] fn test_143() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .bucket("bucket!".to_string()) @@ -4061,7 +3919,6 @@ mod test { /// vanilla virtual addressing@us-west-2 #[test] fn test_144() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4096,7 +3953,6 @@ mod test { /// virtual addressing + dualstack@us-west-2 #[test] fn test_145() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4131,7 +3987,6 @@ mod test { /// accelerate + dualstack@us-west-2 #[test] fn test_146() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4166,7 +4021,6 @@ mod test { /// accelerate (dualstack=false)@us-west-2 #[test] fn test_147() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4201,7 +4055,6 @@ mod test { /// virtual addressing + fips@us-west-2 #[test] fn test_148() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4236,7 +4089,6 @@ mod test { /// virtual addressing + dualstack + fips@us-west-2 #[test] fn test_149() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4271,7 +4123,6 @@ mod test { /// accelerate + fips = error@us-west-2 #[test] fn test_150() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4290,7 +4141,6 @@ mod test { /// vanilla virtual addressing@cn-north-1 #[test] fn test_151() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4325,7 +4175,6 @@ mod test { /// virtual addressing + dualstack@cn-north-1 #[test] fn test_152() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4360,7 +4209,6 @@ mod test { /// accelerate (dualstack=false)@cn-north-1 #[test] fn test_153() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4379,7 +4227,6 @@ mod test { /// virtual addressing + fips@cn-north-1 #[test] fn test_154() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4398,7 +4245,6 @@ mod test { /// vanilla virtual addressing@af-south-1 #[test] fn test_155() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4433,7 +4279,6 @@ mod test { /// virtual addressing + dualstack@af-south-1 #[test] fn test_156() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4468,7 +4313,6 @@ mod test { /// accelerate + dualstack@af-south-1 #[test] fn test_157() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4503,7 +4347,6 @@ mod test { /// accelerate (dualstack=false)@af-south-1 #[test] fn test_158() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4538,7 +4381,6 @@ mod test { /// virtual addressing + fips@af-south-1 #[test] fn test_159() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4573,7 +4415,6 @@ mod test { /// virtual addressing + dualstack + fips@af-south-1 #[test] fn test_160() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4608,7 +4449,6 @@ mod test { /// accelerate + fips = error@af-south-1 #[test] fn test_161() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4627,7 +4467,6 @@ mod test { /// vanilla path style@us-west-2 #[test] fn test_162() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4662,7 +4501,6 @@ mod test { /// fips@us-gov-west-2, bucket is not S3-dns-compatible (subdomains) #[test] fn test_163() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket.with.dots".to_string()) @@ -4696,7 +4534,6 @@ mod test { /// path style + accelerate = error@us-west-2 #[test] fn test_164() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4716,7 +4553,6 @@ mod test { /// path style + dualstack@us-west-2 #[test] fn test_165() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4751,7 +4587,6 @@ mod test { /// path style + arn is error@us-west-2 #[test] fn test_166() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:PARTITION:s3-outposts:REGION:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) @@ -4771,7 +4606,6 @@ mod test { /// path style + invalid DNS name@us-west-2 #[test] fn test_167() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99a_b".to_string()) @@ -4806,7 +4640,6 @@ mod test { /// no path style + invalid DNS name@us-west-2 #[test] fn test_168() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99a_b".to_string()) @@ -4840,7 +4673,6 @@ mod test { /// vanilla path style@cn-north-1 #[test] fn test_169() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4875,7 +4707,6 @@ mod test { /// path style + fips@cn-north-1 #[test] fn test_170() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4894,7 +4725,6 @@ mod test { /// path style + accelerate = error@cn-north-1 #[test] fn test_171() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -4914,7 +4744,6 @@ mod test { /// path style + dualstack@cn-north-1 #[test] fn test_172() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -4949,7 +4778,6 @@ mod test { /// path style + arn is error@cn-north-1 #[test] fn test_173() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:PARTITION:s3-outposts:REGION:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) @@ -4969,7 +4797,6 @@ mod test { /// path style + invalid DNS name@cn-north-1 #[test] fn test_174() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99a_b".to_string()) @@ -5004,7 +4831,6 @@ mod test { /// no path style + invalid DNS name@cn-north-1 #[test] fn test_175() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99a_b".to_string()) @@ -5038,7 +4864,6 @@ mod test { /// vanilla path style@af-south-1 #[test] fn test_176() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5073,7 +4898,6 @@ mod test { /// path style + fips@af-south-1 #[test] fn test_177() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5108,7 +4932,6 @@ mod test { /// path style + accelerate = error@af-south-1 #[test] fn test_178() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -5128,7 +4951,6 @@ mod test { /// path style + dualstack@af-south-1 #[test] fn test_179() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5163,7 +4985,6 @@ mod test { /// path style + arn is error@af-south-1 #[test] fn test_180() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:PARTITION:s3-outposts:REGION:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) @@ -5183,7 +5004,6 @@ mod test { /// path style + invalid DNS name@af-south-1 #[test] fn test_181() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99a_b".to_string()) @@ -5218,7 +5038,6 @@ mod test { /// no path style + invalid DNS name@af-south-1 #[test] fn test_182() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("99a_b".to_string()) @@ -5252,7 +5071,6 @@ mod test { /// virtual addressing + private link@us-west-2 #[test] fn test_183() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5288,7 +5106,6 @@ mod test { /// path style + private link@us-west-2 #[test] fn test_184() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5324,7 +5141,6 @@ mod test { /// SDK::Host + FIPS@us-west-2 #[test] fn test_185() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5344,7 +5160,6 @@ mod test { /// SDK::Host + DualStack@us-west-2 #[test] fn test_186() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5365,7 +5180,6 @@ mod test { /// SDK::HOST + accelerate@us-west-2 #[test] fn test_187() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -5385,7 +5199,6 @@ mod test { /// SDK::Host + access point ARN@us-west-2 #[test] fn test_188() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -5421,7 +5234,6 @@ mod test { /// virtual addressing + private link@cn-north-1 #[test] fn test_189() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5457,7 +5269,6 @@ mod test { /// path style + private link@cn-north-1 #[test] fn test_190() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5493,7 +5304,6 @@ mod test { /// FIPS@cn-north-1 #[test] fn test_191() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5512,7 +5322,6 @@ mod test { /// SDK::Host + DualStack@cn-north-1 #[test] fn test_192() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5533,7 +5342,6 @@ mod test { /// SDK::HOST + accelerate@cn-north-1 #[test] fn test_193() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -5554,7 +5362,6 @@ mod test { /// SDK::Host + access point ARN@cn-north-1 #[test] fn test_194() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint".to_string()) @@ -5590,7 +5397,6 @@ mod test { /// virtual addressing + private link@af-south-1 #[test] fn test_195() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5626,7 +5432,6 @@ mod test { /// path style + private link@af-south-1 #[test] fn test_196() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5662,7 +5467,6 @@ mod test { /// SDK::Host + FIPS@af-south-1 #[test] fn test_197() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5682,7 +5486,6 @@ mod test { /// SDK::Host + DualStack@af-south-1 #[test] fn test_198() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("bucket-name".to_string()) @@ -5703,7 +5506,6 @@ mod test { /// SDK::HOST + accelerate@af-south-1 #[test] fn test_199() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("bucket-name".to_string()) @@ -5724,7 +5526,6 @@ mod test { /// SDK::Host + access point ARN@af-south-1 #[test] fn test_200() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:af-south-1:123456789012:accesspoint:myendpoint".to_string()) @@ -5760,7 +5561,6 @@ mod test { /// vanilla access point arn@us-west-2 #[test] fn test_201() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -5795,7 +5595,6 @@ mod test { /// access point arn + FIPS@us-west-2 #[test] fn test_202() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -5830,7 +5629,6 @@ mod test { /// access point arn + accelerate = error@us-west-2 #[test] fn test_203() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -5850,7 +5648,6 @@ mod test { /// access point arn + FIPS + DualStack@us-west-2 #[test] fn test_204() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint".to_string()) @@ -5886,7 +5683,6 @@ mod test { /// vanilla access point arn@cn-north-1 #[test] fn test_205() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint".to_string()) @@ -5921,7 +5717,6 @@ mod test { /// access point arn + FIPS@cn-north-1 #[test] fn test_206() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint".to_string()) @@ -5940,7 +5735,6 @@ mod test { /// access point arn + accelerate = error@cn-north-1 #[test] fn test_207() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint".to_string()) @@ -5960,7 +5754,6 @@ mod test { /// access point arn + FIPS + DualStack@cn-north-1 #[test] fn test_208() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint".to_string()) @@ -5979,7 +5772,6 @@ mod test { /// vanilla access point arn@af-south-1 #[test] fn test_209() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:af-south-1:123456789012:accesspoint:myendpoint".to_string()) @@ -6014,7 +5806,6 @@ mod test { /// access point arn + FIPS@af-south-1 #[test] fn test_210() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:af-south-1:123456789012:accesspoint:myendpoint".to_string()) @@ -6049,7 +5840,6 @@ mod test { /// access point arn + accelerate = error@af-south-1 #[test] fn test_211() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .bucket("arn:aws:s3:af-south-1:123456789012:accesspoint:myendpoint".to_string()) @@ -6069,7 +5859,6 @@ mod test { /// access point arn + FIPS + DualStack@af-south-1 #[test] fn test_212() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3:af-south-1:123456789012:accesspoint:myendpoint".to_string()) @@ -6105,7 +5894,6 @@ mod test { /// S3 outposts vanilla test #[test] fn test_213() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6140,7 +5928,6 @@ mod test { /// S3 outposts custom endpoint #[test] fn test_214() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6175,7 +5962,6 @@ mod test { /// outposts arn with region mismatch and UseArnRegion=false #[test] fn test_215() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) @@ -6198,7 +5984,6 @@ mod test { /// outposts arn with region mismatch, custom region and UseArnRegion=false #[test] fn test_216() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) @@ -6222,7 +6007,6 @@ mod test { /// outposts arn with region mismatch and UseArnRegion=true #[test] fn test_217() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) @@ -6259,7 +6043,6 @@ mod test { /// outposts arn with region mismatch and UseArnRegion unset #[test] fn test_218() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) @@ -6295,7 +6078,6 @@ mod test { /// outposts arn with partition mismatch and UseArnRegion=true #[test] fn test_219() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) @@ -6315,7 +6097,6 @@ mod test { /// ARN with UseGlobalEndpoint and use-east-1 region uses the regional endpoint #[test] fn test_220() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_global_endpoint(true) @@ -6351,7 +6132,6 @@ mod test { /// S3 outposts does not support dualstack #[test] fn test_221() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -6369,7 +6149,6 @@ mod test { /// S3 outposts does not support fips #[test] fn test_222() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -6387,7 +6166,6 @@ mod test { /// S3 outposts does not support accelerate #[test] fn test_223() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -6405,7 +6183,6 @@ mod test { /// validates against subresource #[test] fn test_224() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6424,7 +6201,6 @@ mod test { /// object lambda @us-east-1 #[test] fn test_225() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -6459,7 +6235,6 @@ mod test { /// object lambda @us-west-2 #[test] fn test_226() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6494,7 +6269,6 @@ mod test { /// object lambda, colon resource deliminator @us-west-2 #[test] fn test_227() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6529,7 +6303,6 @@ mod test { /// object lambda @us-east-1, client region us-west-2, useArnRegion=true #[test] fn test_228() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6564,7 +6337,6 @@ mod test { /// object lambda @us-east-1, client region s3-external-1, useArnRegion=true #[test] fn test_229() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("s3-external-1".to_string()) .use_fips(false) @@ -6599,7 +6371,6 @@ mod test { /// object lambda @us-east-1, client region s3-external-1, useArnRegion=false #[test] fn test_230() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("s3-external-1".to_string()) .use_fips(false) @@ -6621,7 +6392,6 @@ mod test { /// object lambda @us-east-1, client region aws-global, useArnRegion=true #[test] fn test_231() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -6656,7 +6426,6 @@ mod test { /// object lambda @us-east-1, client region aws-global, useArnRegion=false #[test] fn test_232() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -6678,7 +6447,6 @@ mod test { /// object lambda @cn-north-1, client region us-west-2 (cross partition), useArnRegion=true #[test] fn test_233() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -6697,7 +6465,6 @@ mod test { /// object lambda with dualstack #[test] fn test_234() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6716,7 +6483,6 @@ mod test { /// object lambda @us-gov-east-1 #[test] fn test_235() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -6751,7 +6517,6 @@ mod test { /// object lambda @us-gov-east-1, with fips #[test] fn test_236() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -6786,7 +6551,6 @@ mod test { /// object lambda @cn-north-1, with fips #[test] fn test_237() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -6805,7 +6569,6 @@ mod test { /// object lambda with accelerate #[test] fn test_238() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6824,7 +6587,6 @@ mod test { /// object lambda with invalid arn - bad service and someresource #[test] fn test_239() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6846,7 +6608,6 @@ mod test { /// object lambda with invalid arn - invalid resource #[test] fn test_240() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6868,7 +6629,6 @@ mod test { /// object lambda with invalid arn - missing region #[test] fn test_241() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6888,7 +6648,6 @@ mod test { /// object lambda with invalid arn - missing account-id #[test] fn test_242() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6907,7 +6666,6 @@ mod test { /// object lambda with invalid arn - account id contains invalid characters #[test] fn test_243() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6929,7 +6687,6 @@ mod test { /// object lambda with invalid arn - missing access point name #[test] fn test_244() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6951,7 +6708,6 @@ mod test { /// object lambda with invalid arn - access point name contains invalid character: * #[test] fn test_245() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6973,7 +6729,6 @@ mod test { /// object lambda with invalid arn - access point name contains invalid character: . #[test] fn test_246() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -6995,7 +6750,6 @@ mod test { /// object lambda with invalid arn - access point name contains sub resources #[test] fn test_247() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -7017,7 +6771,6 @@ mod test { /// object lambda with custom endpoint #[test] fn test_248() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -7053,7 +6806,6 @@ mod test { /// object lambda arn with region mismatch and UseArnRegion=false #[test] fn test_249() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .bucket("arn:aws:s3-object-lambda:us-east-1:123456789012:accesspoint/mybanner".to_string()) @@ -7076,7 +6828,6 @@ mod test { /// WriteGetObjectResponse @ us-west-2 #[test] fn test_250() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .use_object_lambda_endpoint(true) @@ -7110,7 +6861,6 @@ mod test { /// WriteGetObjectResponse with custom endpoint #[test] fn test_251() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .use_object_lambda_endpoint(true) @@ -7145,7 +6895,6 @@ mod test { /// WriteGetObjectResponse @ us-east-1 #[test] fn test_252() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .use_object_lambda_endpoint(true) @@ -7179,7 +6928,6 @@ mod test { /// WriteGetObjectResponse with fips #[test] fn test_253() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .use_object_lambda_endpoint(true) @@ -7213,7 +6961,6 @@ mod test { /// WriteGetObjectResponse with dualstack #[test] fn test_254() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .use_object_lambda_endpoint(true) @@ -7231,7 +6978,6 @@ mod test { /// WriteGetObjectResponse with accelerate #[test] fn test_255() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(true) .use_object_lambda_endpoint(true) @@ -7249,7 +6995,6 @@ mod test { /// WriteGetObjectResponse with fips in CN #[test] fn test_256() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .region("cn-north-1".to_string()) @@ -7267,7 +7012,6 @@ mod test { /// WriteGetObjectResponse with invalid partition #[test] fn test_257() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .use_object_lambda_endpoint(true) @@ -7286,7 +7030,6 @@ mod test { /// WriteGetObjectResponse with an unknown partition #[test] fn test_258() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .accelerate(false) .use_object_lambda_endpoint(true) @@ -7320,7 +7063,6 @@ mod test { /// S3 Outposts bucketAlias Real Outpost Prod us-west-1 #[test] fn test_259() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .bucket("test-accessp-o0b1d075431d83bebde8xz5w8ijx1qzlbp3i3kuse10--op-s3".to_string()) @@ -7347,7 +7089,6 @@ mod test { /// S3 Outposts bucketAlias Real Outpost Prod ap-east-1 #[test] fn test_260() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .bucket("test-accessp-o0b1d075431d83bebde8xz5w8ijx1qzlbp3i3kuse10--op-s3".to_string()) @@ -7374,7 +7115,6 @@ mod test { /// S3 Outposts bucketAlias Ec2 Outpost Prod us-east-1 #[test] fn test_261() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("test-accessp-e0000075431d83bebde8xz5w8ijx1qzlbp3i3kuse10--op-s3".to_string()) @@ -7408,7 +7148,6 @@ mod test { /// S3 Outposts bucketAlias Ec2 Outpost Prod me-south-1 #[test] fn test_262() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .bucket("test-accessp-e0000075431d83bebde8xz5w8ijx1qzlbp3i3kuse10--op-s3".to_string()) @@ -7442,7 +7181,6 @@ mod test { /// S3 Outposts bucketAlias Real Outpost Beta #[test] fn test_263() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("test-accessp-o0b1d075431d83bebde8xz5w8ijx1qzlbp3i3kbeta0--op-s3".to_string()) @@ -7477,7 +7215,6 @@ mod test { /// S3 Outposts bucketAlias Ec2 Outpost Beta #[test] fn test_264() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("161743052723-e00000136899934034jeahy1t8gpzpbwjj8kb7beta0--op-s3".to_string()) @@ -7513,7 +7250,6 @@ mod test { /// S3 Outposts bucketAlias - No endpoint set for beta #[test] fn test_265() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("test-accessp-o0b1d075431d83bebde8xz5w8ijx1qzlbp3i3kbeta0--op-s3".to_string()) @@ -7533,7 +7269,6 @@ mod test { /// S3 Outposts bucketAlias Invalid hardware type #[test] fn test_266() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("test-accessp-h0000075431d83bebde8xz5w8ijx1qzlbp3i3kuse10--op-s3".to_string()) @@ -7556,7 +7291,6 @@ mod test { /// S3 Outposts bucketAlias Special character in Outpost Arn #[test] fn test_267() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("test-accessp-o00000754%1d83bebde8xz5w8ijx1qzlbp3i3kuse10--op-s3".to_string()) @@ -7577,7 +7311,6 @@ mod test { /// S3 Outposts bucketAlias - No endpoint set for beta #[test] fn test_268() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .bucket("test-accessp-e0b1d075431d83bebde8xz5w8ijx1qzlbp3i3ebeta0--op-s3".to_string()) @@ -7597,7 +7330,6 @@ mod test { /// S3 Snow with bucket #[test] fn test_269() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -7632,7 +7364,6 @@ mod test { /// S3 Snow without bucket #[test] fn test_270() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .endpoint("https://10.0.1.12:433".to_string()) @@ -7666,7 +7397,6 @@ mod test { /// S3 Snow no port #[test] fn test_271() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -7701,7 +7431,6 @@ mod test { /// S3 Snow dns endpoint #[test] fn test_272() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -7734,6 +7463,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Simple Storage Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -7818,27 +7611,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/s3/src/operation/create_multipart_upload.rs b/sdk/s3/src/operation/create_multipart_upload.rs index 3f85cddd5b5d..ae05fad9dfc2 100644 --- a/sdk/s3/src/operation/create_multipart_upload.rs +++ b/sdk/s3/src/operation/create_multipart_upload.rs @@ -283,9 +283,7 @@ mod create_multipart_upload_request_test { #[allow(unused_mut)] async fn create_multipart_upload_uri_construction_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/s3/src/operation/head_object.rs b/sdk/s3/src/operation/head_object.rs index 006b494fab21..9e6ae6c05048 100644 --- a/sdk/s3/src/operation/head_object.rs +++ b/sdk/s3/src/operation/head_object.rs @@ -289,9 +289,7 @@ mod head_object_request_test { #[allow(unused_mut)] async fn head_object_uri_encoding_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/s3/src/operation/put_bucket_lifecycle_configuration.rs b/sdk/s3/src/operation/put_bucket_lifecycle_configuration.rs index 8f9d53640ffd..ac3c94a73465 100644 --- a/sdk/s3/src/operation/put_bucket_lifecycle_configuration.rs +++ b/sdk/s3/src/operation/put_bucket_lifecycle_configuration.rs @@ -304,9 +304,7 @@ mod put_bucket_lifecycle_configuration_request_test { #[allow(unused_mut)] async fn put_bucket_lifecycle_configuration_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/s3/src/operation/put_object.rs b/sdk/s3/src/operation/put_object.rs index 10a5601ce184..60746e4262b7 100644 --- a/sdk/s3/src/operation/put_object.rs +++ b/sdk/s3/src/operation/put_object.rs @@ -299,9 +299,7 @@ mod put_object_request_test { #[allow(unused_mut)] async fn dont_send_duplicate_content_type_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); @@ -326,9 +324,7 @@ mod put_object_request_test { #[allow(unused_mut)] async fn dont_send_duplicate_content_length_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1")); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/s3control/src/config.rs b/sdk/s3control/src/config.rs index 9d199839a3e9..16be24849ce8 100644 --- a/sdk/s3control/src/config.rs +++ b/sdk/s3control/src/config.rs @@ -251,63 +251,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_s3control`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_s3control::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_s3control::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_s3control::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_s3control::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_s3control::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_s3control`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -977,11 +960,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1179,7 +1161,7 @@ impl ::aws_smithy_types::config_bag::Storable for UseArnRegion { /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/s3control/src/config/endpoint.rs b/sdk/s3control/src/config/endpoint.rs index 8b23fc7c5421..8855b51da352 100644 --- a/sdk/s3control/src/config/endpoint.rs +++ b/sdk/s3control/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// Vanilla outposts without ARN region + access point ARN@us-west-2 #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -46,7 +46,6 @@ mod test { /// Vanilla outposts with ARN region + access point ARN@us-west-2 #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -83,7 +82,6 @@ mod test { /// accept an access point ARN@us-west-2 #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -120,7 +118,6 @@ mod test { /// vanilla outposts china@cn-north-1 #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws-cn:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -157,7 +154,6 @@ mod test { /// gov region@us-west-2 #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -194,7 +190,6 @@ mod test { /// gov cloud with fips@us-west-2 #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -231,7 +226,6 @@ mod test { /// govcloud with fips + arn region@us-gov-west-1 #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name( "arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string(), @@ -270,7 +264,6 @@ mod test { /// gov region@cn-north-1 #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws-cn:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -307,7 +300,6 @@ mod test { /// gov cloud with fips@cn-north-1 #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws-cn:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -344,7 +336,6 @@ mod test { /// govcloud with fips + arn region@us-gov-west-1 #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name( "arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string(), @@ -383,7 +374,6 @@ mod test { /// gov region@af-south-1 #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:af-south-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -420,7 +410,6 @@ mod test { /// gov cloud with fips@af-south-1 #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:af-south-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -457,7 +446,6 @@ mod test { /// govcloud with fips + arn region@us-gov-west-1 #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name( "arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string(), @@ -496,7 +484,6 @@ mod test { /// CreateBucket + OutpostId = outposts endpoint@us-east-2 #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("blah".to_string()) .outpost_id("123".to_string()) @@ -531,7 +518,6 @@ mod test { /// CreateBucket + OutpostId with fips = outposts endpoint@us-east-2 #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("blah".to_string()) .outpost_id("123".to_string()) @@ -566,7 +552,6 @@ mod test { /// CreateBucket without OutpostId = regular endpoint@us-east-2 #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("blah".to_string()) .region("us-east-2".to_string()) @@ -600,7 +585,6 @@ mod test { /// ListRegionalBuckets + OutpostId = outposts endpoint@us-east-2 #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .outpost_id("op-123".to_string()) @@ -635,7 +619,6 @@ mod test { /// ListRegionalBuckets without OutpostId = regular endpoint@us-east-2 #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .region("us-east-2".to_string()) @@ -669,7 +652,6 @@ mod test { /// ListRegionalBucket + OutpostId with fips = outposts endpoint@us-east-2 #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .outpost_id("op-123".to_string()) @@ -704,7 +686,6 @@ mod test { /// outpost access points do not support dualstack@us-west-2 #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -726,7 +707,6 @@ mod test { /// outpost access points do not support dualstack@cn-north-1 #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -748,7 +728,6 @@ mod test { /// outpost access points do not support dualstack@af-south-1 #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -770,7 +749,6 @@ mod test { /// invalid ARN: must be include outpost ID@us-west-2 #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost".to_string()) .account_id("123456789012".to_string()) @@ -790,7 +768,6 @@ mod test { /// invalid ARN: must specify access point@us-west-2 #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456".to_string()) .region("us-west-2".to_string()) @@ -809,7 +786,6 @@ mod test { /// invalid ARN@us-west-2 #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:myaccesspoint".to_string()) .region("us-west-2".to_string()) @@ -827,7 +803,6 @@ mod test { /// when set, AccountId drives AP construction@us-west-2 #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("myaccesspoint".to_string()) .account_id("myid-1234".to_string()) @@ -862,7 +837,6 @@ mod test { /// Account ID set inline and in ARN but they both match@us-west-2 #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -900,7 +874,6 @@ mod test { /// Account ID set inline and in ARN and they do not match@us-west-2 #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("999999999999".to_string()) @@ -923,7 +896,6 @@ mod test { /// get access point prefixed with account id using endpoint url@us-west-2 #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("apname".to_string()) .account_id("123456789012".to_string()) @@ -959,7 +931,6 @@ mod test { /// endpoint url with s3-outposts@us-west-2 #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -997,7 +968,6 @@ mod test { /// access point name with a bucket arn@us-west-2 #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .endpoint("beta.example.com".to_string()) @@ -1017,7 +987,6 @@ mod test { /// bucket arn with access point name@us-west-2 #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .endpoint("beta.example.com".to_string()) @@ -1041,7 +1010,6 @@ mod test { /// create bucket with outposts@us-west-2 #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucketname".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -1077,7 +1045,6 @@ mod test { /// get bucket with endpoint_url@us-west-2 #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -1114,7 +1081,6 @@ mod test { /// ListRegionalBucket + OutpostId endpoint url@us-east-2 #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -1150,7 +1116,6 @@ mod test { /// ListRegionalBucket + OutpostId + fips + endpoint url@us-east-2 #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -1186,7 +1151,6 @@ mod test { /// CreateBucket + OutpostId endpoint url@us-east-2 #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("blah".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -1222,7 +1186,6 @@ mod test { /// dualstack cannot be used with outposts when an endpoint URL is set@us-west-2. #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -1244,7 +1207,6 @@ mod test { /// Dual-stack cannot be used with outposts@us-west-2 #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("bucketname".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -1266,7 +1228,6 @@ mod test { /// vanilla bucket arn requires account id@us-west-2 #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -1302,7 +1263,6 @@ mod test { /// bucket arn with UseArnRegion = true (arn region supercedes client configured region)@us-west-2 #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -1338,7 +1298,6 @@ mod test { /// bucket ARN in gov partition (non-fips)@us-gov-east-1 #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-gov-east-1".to_string()) @@ -1374,7 +1333,6 @@ mod test { /// bucket ARN in gov partition with FIPS@us-gov-west-1 #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-us-gov:s3-outposts:us-gov-west-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-gov-west-1".to_string()) @@ -1410,7 +1368,6 @@ mod test { /// bucket ARN in aws partition with FIPS@us-east-2 #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-east-2".to_string()) @@ -1446,7 +1403,6 @@ mod test { /// Outposts do not support dualstack@us-west-2 #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -1466,7 +1422,6 @@ mod test { /// vanilla bucket arn requires account id@cn-north-1 #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-cn:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("cn-north-1".to_string()) @@ -1502,7 +1457,6 @@ mod test { /// bucket arn with UseArnRegion = true (arn region supercedes client configured region)@us-west-2 #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -1538,7 +1492,6 @@ mod test { /// bucket ARN in gov partition (non-fips)@us-gov-east-1 #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-gov-east-1".to_string()) @@ -1574,7 +1527,6 @@ mod test { /// bucket ARN in gov partition with FIPS@us-gov-west-1 #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-us-gov:s3-outposts:us-gov-west-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-gov-west-1".to_string()) @@ -1610,7 +1562,6 @@ mod test { /// bucket ARN in aws partition with FIPS@us-east-2 #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-east-2".to_string()) @@ -1646,7 +1597,6 @@ mod test { /// Outposts do not support dualstack@us-west-2 #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -1666,7 +1616,6 @@ mod test { /// vanilla bucket arn requires account id@af-south-1 #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:af-south-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("af-south-1".to_string()) @@ -1702,7 +1651,6 @@ mod test { /// bucket arn with UseArnRegion = true (arn region supercedes client configured region)@us-west-2 #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -1738,7 +1686,6 @@ mod test { /// bucket ARN in gov partition (non-fips)@us-gov-east-1 #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-gov-east-1".to_string()) @@ -1774,7 +1721,6 @@ mod test { /// bucket ARN in gov partition with FIPS@us-gov-west-1 #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws-us-gov:s3-outposts:us-gov-west-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-gov-west-1".to_string()) @@ -1810,7 +1756,6 @@ mod test { /// bucket ARN in aws partition with FIPS@us-east-2 #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-east-2".to_string()) @@ -1846,7 +1791,6 @@ mod test { /// Outposts do not support dualstack@us-west-2 #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -1866,7 +1810,6 @@ mod test { /// Invalid ARN: missing outpost id and bucket@us-west-2 #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost".to_string()) .region("us-west-2".to_string()) @@ -1885,7 +1828,6 @@ mod test { /// Invalid ARN: missing bucket@us-west-2 #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456".to_string()) .region("us-west-2".to_string()) @@ -1903,7 +1845,6 @@ mod test { /// Invalid ARN: missing outpost and bucket ids@us-west-2 #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:bucket".to_string()) .region("us-west-2".to_string()) @@ -1922,7 +1863,6 @@ mod test { /// Invalid ARN: missing bucket id@us-west-2 #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket".to_string()) .region("us-west-2".to_string()) @@ -1940,7 +1880,6 @@ mod test { /// account id inserted into hostname@us-west-2 #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("1234567890".to_string()) .region("us-west-2".to_string()) @@ -1974,7 +1913,6 @@ mod test { /// account id prefix with dualstack@us-east-1 #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("1234567890".to_string()) .region("us-east-1".to_string()) @@ -2008,7 +1946,6 @@ mod test { /// account id prefix with fips@us-east-1 #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("1234567890".to_string()) .region("us-east-1".to_string()) @@ -2042,7 +1979,6 @@ mod test { /// custom account id prefix with fips@us-east-1 #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .region("us-east-1".to_string()) @@ -2076,7 +2012,6 @@ mod test { /// standard url @ us-east-1 #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .build() @@ -2106,7 +2041,6 @@ mod test { /// fips url @ us-east-1 #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -2137,7 +2071,6 @@ mod test { /// dualstack url @ us-east-1 #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_dual_stack(true) @@ -2168,7 +2101,6 @@ mod test { /// fips,dualstack url @ us-east-1 #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_dual_stack(true) @@ -2200,7 +2132,6 @@ mod test { /// standard url @ cn-north-1 #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .build() @@ -2230,7 +2161,6 @@ mod test { /// fips @ cn-north-1 #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_dual_stack(true) @@ -2246,7 +2176,6 @@ mod test { /// custom account id prefix @us-east-1 #[test] fn test_72() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .region("us-east-1".to_string()) @@ -2280,7 +2209,6 @@ mod test { /// invalid account id prefix @us-east-1 #[test] fn test_73() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("/?invalid¬-host*label".to_string()) .region("us-east-1".to_string()) @@ -2298,7 +2226,6 @@ mod test { /// custom account id prefix with fips@us-east-1 #[test] fn test_74() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .region("us-east-1".to_string()) @@ -2332,7 +2259,6 @@ mod test { /// custom account id prefix with dualstack,fips@us-east-1 #[test] fn test_75() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .region("us-east-1".to_string()) @@ -2366,7 +2292,6 @@ mod test { /// custom account id with custom endpoint #[test] fn test_76() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .region("us-east-1".to_string()) @@ -2399,7 +2324,6 @@ mod test { /// RequiresAccountId with AccountId unset #[test] fn test_77() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .requires_account_id(true) @@ -2414,7 +2338,6 @@ mod test { /// RequiresAccountId with AccountId unset and custom endpoint #[test] fn test_78() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -2431,7 +2354,6 @@ mod test { /// RequiresAccountId with invalid AccountId and custom endpoint #[test] fn test_79() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -2450,7 +2372,6 @@ mod test { /// account id with custom endpoint, fips #[test] fn test_80() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("123456789012".to_string()) .region("us-east-1".to_string()) @@ -2484,7 +2405,6 @@ mod test { /// custom endpoint, fips #[test] fn test_81() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .endpoint("https://example.com".to_string()) @@ -2516,7 +2436,6 @@ mod test { /// custom endpoint, fips #[test] fn test_82() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .endpoint("https://example.com".to_string()) @@ -2548,7 +2467,6 @@ mod test { /// custom endpoint, DualStack #[test] fn test_83() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .endpoint("https://example.com".to_string()) @@ -2569,7 +2487,6 @@ mod test { /// region not set #[test] fn test_84() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -2580,7 +2497,6 @@ mod test { /// invalid partition #[test] fn test_85() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("invalid-region 42".to_string()) .build() @@ -2594,7 +2510,6 @@ mod test { /// ListRegionalBuckets + OutpostId without accountId set. #[test] fn test_86() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .outpost_id("op-123".to_string()) .region("us-east-2".to_string()) @@ -2612,7 +2527,6 @@ mod test { /// ListRegionalBuckets + OutpostId with invalid accountId set. #[test] fn test_87() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("/?invalid¬-host*label".to_string()) .outpost_id("op-123".to_string()) @@ -2633,7 +2547,6 @@ mod test { /// accesspoint set but missing accountId #[test] fn test_88() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("myaccesspoint".to_string()) .region("us-west-2".to_string()) @@ -2651,7 +2564,6 @@ mod test { /// outpost accesspoint ARN with missing accountId #[test] fn test_89() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2::outpost:op-01234567890123456:outpost:op1".to_string()) .region("us-west-2".to_string()) @@ -2669,7 +2581,6 @@ mod test { /// bucket ARN with missing accountId #[test] fn test_90() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2::outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -2687,7 +2598,6 @@ mod test { /// endpoint url with accesspoint (non-arn) #[test] fn test_91() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("apname".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -2723,7 +2633,6 @@ mod test { /// access point name with an accesspoint arn@us-west-2 #[test] fn test_92() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -2760,7 +2669,6 @@ mod test { /// DualStack + Custom endpoint is not supported(non-arn) #[test] fn test_93() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("apname".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -2783,7 +2691,6 @@ mod test { /// get bucket with endpoint_url and dualstack is not supported@us-west-2 #[test] fn test_94() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -2802,7 +2709,6 @@ mod test { /// ListRegionalBuckets + OutpostId with fips in CN. #[test] fn test_95() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("0123456789012".to_string()) .outpost_id("op-123".to_string()) @@ -2821,7 +2727,6 @@ mod test { /// ListRegionalBuckets + invalid OutpostId. #[test] fn test_96() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .account_id("0123456789012".to_string()) .outpost_id("?outpost/invalid+".to_string()) @@ -2841,7 +2746,6 @@ mod test { /// bucket ARN with mismatched accountId #[test] fn test_97() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:999999:outpost:op-01234567890123456:bucket:mybucket".to_string()) .account_id("0123456789012".to_string()) @@ -2863,7 +2767,6 @@ mod test { /// OutpostId with invalid region #[test] fn test_98() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .outpost_id("op-123".to_string()) .region("invalid-region 42".to_string()) @@ -2882,7 +2785,6 @@ mod test { /// OutpostId with RequireAccountId unset #[test] fn test_99() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .outpost_id("op-123".to_string()) .region("us-west-2".to_string()) @@ -2915,7 +2817,6 @@ mod test { /// Outpost Accesspoint ARN with arn region and client region mismatch with UseArnRegion=false #[test] fn test_100() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -2938,7 +2839,6 @@ mod test { /// Outpost Bucket ARN with arn region and client region mismatch with UseArnRegion=false #[test] fn test_101() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .endpoint("https://beta.example.com".to_string()) @@ -2961,7 +2861,6 @@ mod test { /// Accesspoint ARN with region mismatch and UseArnRegion unset #[test] fn test_102() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -2998,7 +2897,6 @@ mod test { /// Bucket ARN with region mismatch and UseArnRegion unset #[test] fn test_103() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -3034,7 +2932,6 @@ mod test { /// Outpost Bucket ARN with partition mismatch with UseArnRegion=true #[test] fn test_104() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -3053,7 +2950,6 @@ mod test { /// Accesspoint ARN with partition mismatch and UseArnRegion=true #[test] fn test_105() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .account_id("123456789012".to_string()) @@ -3073,7 +2969,6 @@ mod test { /// Accesspoint ARN with region mismatch, UseArnRegion=false and custom endpoint #[test] fn test_106() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .access_point_name("arn:aws:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint".to_string()) .region("us-west-2".to_string()) @@ -3096,7 +2991,6 @@ mod test { /// outpost bucket arn@us-west-2 #[test] fn test_107() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .bucket("arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket".to_string()) .region("us-west-2".to_string()) @@ -3132,7 +3026,6 @@ mod test { /// S3 Snow Control with bucket #[test] fn test_108() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -3166,7 +3059,6 @@ mod test { /// S3 Snow Control without bucket #[test] fn test_109() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .endpoint("https://10.0.1.12:433".to_string()) @@ -3199,7 +3091,6 @@ mod test { /// S3 Snow Control with bucket and without port #[test] fn test_110() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -3233,7 +3124,6 @@ mod test { /// S3 Snow Control with bucket and with DNS #[test] fn test_111() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -3267,7 +3157,6 @@ mod test { /// S3 Snow Control with FIPS enabled #[test] fn test_112() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -3285,7 +3174,6 @@ mod test { /// S3 Snow Control with Dualstack enabled #[test] fn test_113() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("snow".to_string()) .bucket("bucketName".to_string()) @@ -3301,6 +3189,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS S3 Control +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -3373,27 +3325,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/s3outposts/src/config.rs b/sdk/s3outposts/src/config.rs index dd22522f5e05..dc34f67ac2d6 100644 --- a/sdk/s3outposts/src/config.rs +++ b/sdk/s3outposts/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_s3outposts`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_s3outposts::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_s3outposts::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_s3outposts::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_s3outposts::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_s3outposts::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_s3outposts`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/s3outposts/src/config/endpoint.rs b/sdk/s3outposts/src/config/endpoint.rs index 1b4f294dbd85..976d69aa7f29 100644 --- a/sdk/s3outposts/src/config/endpoint.rs +++ b/sdk/s3outposts/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon S3 on Outposts +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sagemaker/src/config.rs b/sdk/sagemaker/src/config.rs index bd6b73e6e545..74a86cf42f03 100644 --- a/sdk/sagemaker/src/config.rs +++ b/sdk/sagemaker/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemaker`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sagemaker::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sagemaker::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sagemaker::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sagemaker::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sagemaker::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemaker`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sagemaker/src/config/endpoint.rs b/sdk/sagemaker/src/config/endpoint.rs index 941160740891..38a045557ac5 100644 --- a/sdk/sagemaker/src/config/endpoint.rs +++ b/sdk/sagemaker/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon SageMaker Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sagemakera2iruntime/src/config.rs b/sdk/sagemakera2iruntime/src/config.rs index 5849e6b7e1d1..14b4d65815b4 100644 --- a/sdk/sagemakera2iruntime/src/config.rs +++ b/sdk/sagemakera2iruntime/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakera2iruntime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sagemakera2iruntime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sagemakera2iruntime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sagemakera2iruntime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sagemakera2iruntime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sagemakera2iruntime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakera2iruntime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sagemakera2iruntime/src/config/endpoint.rs b/sdk/sagemakera2iruntime/src/config/endpoint.rs index dbc659313fa2..cafd8fbc3f32 100644 --- a/sdk/sagemakera2iruntime/src/config/endpoint.rs +++ b/sdk/sagemakera2iruntime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Augmented AI Runtime +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sagemakeredge/src/config.rs b/sdk/sagemakeredge/src/config.rs index 3fbccde86437..8accd13d99df 100644 --- a/sdk/sagemakeredge/src/config.rs +++ b/sdk/sagemakeredge/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakeredge`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sagemakeredge::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sagemakeredge::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sagemakeredge::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sagemakeredge::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sagemakeredge::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakeredge`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sagemakeredge/src/config/endpoint.rs b/sdk/sagemakeredge/src/config/endpoint.rs index b46c586cc050..2dc1ef365078 100644 --- a/sdk/sagemakeredge/src/config/endpoint.rs +++ b/sdk/sagemakeredge/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Sagemaker Edge Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sagemakerfeaturestoreruntime/src/config.rs b/sdk/sagemakerfeaturestoreruntime/src/config.rs index 487fa8265e7c..56394a03ad69 100644 --- a/sdk/sagemakerfeaturestoreruntime/src/config.rs +++ b/sdk/sagemakerfeaturestoreruntime/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakerfeaturestoreruntime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sagemakerfeaturestoreruntime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sagemakerfeaturestoreruntime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sagemakerfeaturestoreruntime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sagemakerfeaturestoreruntime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sagemakerfeaturestoreruntime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakerfeaturestoreruntime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sagemakerfeaturestoreruntime/src/config/endpoint.rs b/sdk/sagemakerfeaturestoreruntime/src/config/endpoint.rs index 60156cf41d5e..d7b55c727153 100644 --- a/sdk/sagemakerfeaturestoreruntime/src/config/endpoint.rs +++ b/sdk/sagemakerfeaturestoreruntime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -115,7 +111,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -136,7 +131,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -157,7 +151,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -178,7 +171,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -199,7 +191,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -220,7 +211,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -241,7 +231,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -262,7 +251,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -281,7 +269,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -302,7 +289,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -318,7 +304,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -339,7 +324,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -358,7 +342,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -379,7 +362,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -395,7 +377,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -416,7 +397,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -455,7 +434,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -472,7 +450,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -492,7 +469,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -501,6 +477,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon SageMaker Feature Store Runtime +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -537,27 +577,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sagemakergeospatial/src/config.rs b/sdk/sagemakergeospatial/src/config.rs index afcdc484c344..736717a41be0 100644 --- a/sdk/sagemakergeospatial/src/config.rs +++ b/sdk/sagemakergeospatial/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakergeospatial`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sagemakergeospatial::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sagemakergeospatial::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sagemakergeospatial::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sagemakergeospatial::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sagemakergeospatial::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakergeospatial`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sagemakergeospatial/src/config/endpoint.rs b/sdk/sagemakergeospatial/src/config/endpoint.rs index 63b3ac49534f..512b65e20f51 100644 --- a/sdk/sagemakergeospatial/src/config/endpoint.rs +++ b/sdk/sagemakergeospatial/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon SageMaker geospatial capabilities +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sagemakermetrics/src/config.rs b/sdk/sagemakermetrics/src/config.rs index b27d41246475..109b26781480 100644 --- a/sdk/sagemakermetrics/src/config.rs +++ b/sdk/sagemakermetrics/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakermetrics`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sagemakermetrics::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sagemakermetrics::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sagemakermetrics::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sagemakermetrics::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sagemakermetrics::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakermetrics`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sagemakermetrics/src/config/endpoint.rs b/sdk/sagemakermetrics/src/config/endpoint.rs index 113137eb61fb..4ed5c484ab0f 100644 --- a/sdk/sagemakermetrics/src/config/endpoint.rs +++ b/sdk/sagemakermetrics/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon SageMaker Metrics Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sagemakerruntime/src/config.rs b/sdk/sagemakerruntime/src/config.rs index 4f341234b7f6..653f52ab4811 100644 --- a/sdk/sagemakerruntime/src/config.rs +++ b/sdk/sagemakerruntime/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakerruntime`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sagemakerruntime::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sagemakerruntime::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sagemakerruntime::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sagemakerruntime::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sagemakerruntime::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sagemakerruntime`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sagemakerruntime/src/config/endpoint.rs b/sdk/sagemakerruntime/src/config/endpoint.rs index 8e4b59bd1c0a..152cf2065c3b 100644 --- a/sdk/sagemakerruntime/src/config/endpoint.rs +++ b/sdk/sagemakerruntime/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon SageMaker Runtime +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/savingsplans/src/config.rs b/sdk/savingsplans/src/config.rs index d9843bdfc1e9..9b027102d170 100644 --- a/sdk/savingsplans/src/config.rs +++ b/sdk/savingsplans/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_savingsplans`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_savingsplans::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_savingsplans::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_savingsplans::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_savingsplans::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_savingsplans::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_savingsplans`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/savingsplans/src/config/endpoint.rs b/sdk/savingsplans/src/config/endpoint.rs index 654c746d6f6b..c8c679f0725d 100644 --- a/sdk/savingsplans/src/config/endpoint.rs +++ b/sdk/savingsplans/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -155,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -176,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -197,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -218,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -239,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -260,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -281,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -302,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -321,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -342,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -358,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -379,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -398,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -419,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -435,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -456,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -476,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -495,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -512,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -532,7 +508,6 @@ mod test { /// Missing region #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -541,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Savings Plans +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -577,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/scheduler/src/config.rs b/sdk/scheduler/src/config.rs index 257a6c99145d..bc6583feaf50 100644 --- a/sdk/scheduler/src/config.rs +++ b/sdk/scheduler/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_scheduler`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_scheduler::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_scheduler::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_scheduler::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_scheduler::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_scheduler::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_scheduler`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/scheduler/src/config/endpoint.rs b/sdk/scheduler/src/config/endpoint.rs index 6a52aa55a413..75c73559e057 100644 --- a/sdk/scheduler/src/config/endpoint.rs +++ b/sdk/scheduler/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon EventBridge Scheduler +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/schemas/src/config.rs b/sdk/schemas/src/config.rs index 35c47179df1f..1099c931403d 100644 --- a/sdk/schemas/src/config.rs +++ b/sdk/schemas/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_schemas`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_schemas::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_schemas::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_schemas::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_schemas::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_schemas::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_schemas`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/schemas/src/config/endpoint.rs b/sdk/schemas/src/config/endpoint.rs index 2f2160b3a899..450acb9fb850 100644 --- a/sdk/schemas/src/config/endpoint.rs +++ b/sdk/schemas/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -751,7 +716,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -771,7 +735,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -790,7 +753,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +769,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -827,7 +788,6 @@ mod test { /// Missing region #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -836,6 +796,70 @@ mod test { } } +/// Endpoint resolver trait specific to Schemas +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -872,27 +896,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/secretsmanager/src/config.rs b/sdk/secretsmanager/src/config.rs index f51ec7e4a62b..593aae1008ed 100644 --- a/sdk/secretsmanager/src/config.rs +++ b/sdk/secretsmanager/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_secretsmanager`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_secretsmanager::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_secretsmanager::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_secretsmanager::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_secretsmanager::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_secretsmanager::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_secretsmanager`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/secretsmanager/src/config/endpoint.rs b/sdk/secretsmanager/src/config/endpoint.rs index e7b16eb7d667..bd74d16f901f 100644 --- a/sdk/secretsmanager/src/config/endpoint.rs +++ b/sdk/secretsmanager/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Secrets Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/securityhub/src/config.rs b/sdk/securityhub/src/config.rs index 7aa65a0bfbf9..caf609b5a4a1 100644 --- a/sdk/securityhub/src/config.rs +++ b/sdk/securityhub/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_securityhub`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_securityhub::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_securityhub::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_securityhub::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_securityhub::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_securityhub::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_securityhub`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/securityhub/src/config/endpoint.rs b/sdk/securityhub/src/config/endpoint.rs index 1334f3f38c4b..afa877ad3a3e 100644 --- a/sdk/securityhub/src/config/endpoint.rs +++ b/sdk/securityhub/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS SecurityHub +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/securitylake/src/config.rs b/sdk/securitylake/src/config.rs index 971eb882aba1..a1231569852a 100644 --- a/sdk/securitylake/src/config.rs +++ b/sdk/securitylake/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_securitylake`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_securitylake::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_securitylake::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_securitylake::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_securitylake::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_securitylake::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_securitylake`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/securitylake/src/config/endpoint.rs b/sdk/securitylake/src/config/endpoint.rs index 857a8825386e..61dde0f40d97 100644 --- a/sdk/securitylake/src/config/endpoint.rs +++ b/sdk/securitylake/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Security Lake +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/serverlessapplicationrepository/src/config.rs b/sdk/serverlessapplicationrepository/src/config.rs index e343da5d9d8c..ad8aede73109 100644 --- a/sdk/serverlessapplicationrepository/src/config.rs +++ b/sdk/serverlessapplicationrepository/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_serverlessapplicationrepository`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_serverlessapplicationrepository::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_serverlessapplicationrepository::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_serverlessapplicationrepository::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_serverlessapplicationrepository::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_serverlessapplicationrepository::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_serverlessapplicationrepository`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/serverlessapplicationrepository/src/config/endpoint.rs b/sdk/serverlessapplicationrepository/src/config/endpoint.rs index d39813e90fef..2da65fdf587c 100644 --- a/sdk/serverlessapplicationrepository/src/config/endpoint.rs +++ b/sdk/serverlessapplicationrepository/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWSServerlessApplicationRepository +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/servicecatalog/src/config.rs b/sdk/servicecatalog/src/config.rs index 76aed70da519..38edd917adaa 100644 --- a/sdk/servicecatalog/src/config.rs +++ b/sdk/servicecatalog/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicecatalog`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_servicecatalog::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_servicecatalog::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_servicecatalog::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_servicecatalog::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_servicecatalog::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicecatalog`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/servicecatalog/src/config/endpoint.rs b/sdk/servicecatalog/src/config/endpoint.rs index 60babb930b62..ec8069236055 100644 --- a/sdk/servicecatalog/src/config/endpoint.rs +++ b/sdk/servicecatalog/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Service Catalog +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/servicecatalogappregistry/src/config.rs b/sdk/servicecatalogappregistry/src/config.rs index 81a110fccc99..2601699a95b5 100644 --- a/sdk/servicecatalogappregistry/src/config.rs +++ b/sdk/servicecatalogappregistry/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicecatalogappregistry`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_servicecatalogappregistry::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_servicecatalogappregistry::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_servicecatalogappregistry::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_servicecatalogappregistry::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_servicecatalogappregistry::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicecatalogappregistry`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/servicecatalogappregistry/src/config/endpoint.rs b/sdk/servicecatalogappregistry/src/config/endpoint.rs index d6d2faa326e9..ec75b268647f 100644 --- a/sdk/servicecatalogappregistry/src/config/endpoint.rs +++ b/sdk/servicecatalogappregistry/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Service Catalog App Registry +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/servicediscovery/src/config.rs b/sdk/servicediscovery/src/config.rs index ad9e4addaa35..8adf9aef3c9f 100644 --- a/sdk/servicediscovery/src/config.rs +++ b/sdk/servicediscovery/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicediscovery`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_servicediscovery::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_servicediscovery::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_servicediscovery::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_servicediscovery::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_servicediscovery::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicediscovery`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/servicediscovery/src/config/endpoint.rs b/sdk/servicediscovery/src/config/endpoint.rs index 9053140b9382..e6d3760def8b 100644 --- a/sdk/servicediscovery/src/config/endpoint.rs +++ b/sdk/servicediscovery/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -981,7 +935,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1000,7 +953,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1017,7 +969,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1037,7 +988,6 @@ mod test { /// Missing region #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1046,6 +996,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Cloud Map +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1082,27 +1096,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/servicequotas/src/config.rs b/sdk/servicequotas/src/config.rs index a30d8a142cf4..0e0aa6a77113 100644 --- a/sdk/servicequotas/src/config.rs +++ b/sdk/servicequotas/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicequotas`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_servicequotas::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_servicequotas::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_servicequotas::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_servicequotas::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_servicequotas::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_servicequotas`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/servicequotas/src/config/endpoint.rs b/sdk/servicequotas/src/config/endpoint.rs index c4ea58daa451..7753d3831f84 100644 --- a/sdk/servicequotas/src/config/endpoint.rs +++ b/sdk/servicequotas/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -784,7 +748,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -821,7 +783,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -861,7 +821,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -898,7 +856,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -918,7 +875,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -937,7 +893,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +909,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -974,7 +928,6 @@ mod test { /// Missing region #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -983,6 +936,70 @@ mod test { } } +/// Endpoint resolver trait specific to Service Quotas +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1019,27 +1036,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ses/src/config.rs b/sdk/ses/src/config.rs index 72084ab5fb98..ebeb9d118dd8 100644 --- a/sdk/ses/src/config.rs +++ b/sdk/ses/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ses`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ses::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ses::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ses::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ses::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ses::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ses`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ses/src/config/endpoint.rs b/sdk/ses/src/config/endpoint.rs index fad19bb87516..d9e3edf072f1 100644 --- a/sdk/ses/src/config/endpoint.rs +++ b/sdk/ses/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Simple Email Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sesv2/src/config.rs b/sdk/sesv2/src/config.rs index 22ccc943fdd4..e0738b7de2a4 100644 --- a/sdk/sesv2/src/config.rs +++ b/sdk/sesv2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sesv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sesv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sesv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sesv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sesv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sesv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sesv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sesv2/src/config/endpoint.rs b/sdk/sesv2/src/config/endpoint.rs index fad19bb87516..d9e3edf072f1 100644 --- a/sdk/sesv2/src/config/endpoint.rs +++ b/sdk/sesv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -742,7 +708,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -763,7 +728,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -779,7 +743,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -800,7 +763,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -819,7 +781,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -840,7 +801,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -856,7 +816,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -877,7 +836,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -897,7 +855,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -916,7 +873,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -933,7 +889,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -953,7 +908,6 @@ mod test { /// Missing region #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -962,6 +916,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Simple Email Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -998,27 +1016,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sfn/src/config.rs b/sdk/sfn/src/config.rs index ae58e81ed2a9..344c9e45d41c 100644 --- a/sdk/sfn/src/config.rs +++ b/sdk/sfn/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sfn`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sfn::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sfn::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sfn::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sfn::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sfn::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sfn`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sfn/src/config/endpoint.rs b/sdk/sfn/src/config/endpoint.rs index 6e22fe144d9e..fc6f19b380f8 100644 --- a/sdk/sfn/src/config/endpoint.rs +++ b/sdk/sfn/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Step Functions +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/shield/src/config.rs b/sdk/shield/src/config.rs index a2b956179e23..3a344f333fb7 100644 --- a/sdk/shield/src/config.rs +++ b/sdk/shield/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_shield`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_shield::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_shield::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_shield::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_shield::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_shield::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_shield`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/shield/src/config/endpoint.rs b/sdk/shield/src/config/endpoint.rs index ab8f27af6820..3e1318ef1817 100644 --- a/sdk/shield/src/config/endpoint.rs +++ b/sdk/shield/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region aws-global with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -71,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -92,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -123,7 +120,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -144,7 +140,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -175,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -196,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -217,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -238,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -259,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -280,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -301,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -322,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -343,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -362,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -383,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -399,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -420,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -439,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -460,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -476,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -497,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -517,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -536,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -553,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -573,7 +548,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -582,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Shield +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -618,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/signer/src/config.rs b/sdk/signer/src/config.rs index 4b4b055fb121..4ddb731a466a 100644 --- a/sdk/signer/src/config.rs +++ b/sdk/signer/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_signer`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_signer::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_signer::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_signer::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_signer::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_signer::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_signer`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/signer/src/config/endpoint.rs b/sdk/signer/src/config/endpoint.rs index a0a548ee0beb..b69ad75f2b09 100644 --- a/sdk/signer/src/config/endpoint.rs +++ b/sdk/signer/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Signer +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/simspaceweaver/src/config.rs b/sdk/simspaceweaver/src/config.rs index 49860163b2af..fc53cfde9a84 100644 --- a/sdk/simspaceweaver/src/config.rs +++ b/sdk/simspaceweaver/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_simspaceweaver`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_simspaceweaver::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_simspaceweaver::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_simspaceweaver::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_simspaceweaver::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_simspaceweaver::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_simspaceweaver`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/simspaceweaver/src/config/endpoint.rs b/sdk/simspaceweaver/src/config/endpoint.rs index 8c77ef423b78..ca383bc9caef 100644 --- a/sdk/simspaceweaver/src/config/endpoint.rs +++ b/sdk/simspaceweaver/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS SimSpace Weaver +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sms/src/config.rs b/sdk/sms/src/config.rs index 4c57e548887c..9b72c0a9d17f 100644 --- a/sdk/sms/src/config.rs +++ b/sdk/sms/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sms`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sms::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sms::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sms::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sms::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sms::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sms`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sms/src/config/endpoint.rs b/sdk/sms/src/config/endpoint.rs index f704b8facf85..42aabcd4651f 100644 --- a/sdk/sms/src/config/endpoint.rs +++ b/sdk/sms/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -805,7 +768,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -842,7 +803,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -960,7 +915,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -979,7 +933,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -996,7 +949,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1016,7 +968,6 @@ mod test { /// Missing region #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1025,6 +976,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Server Migration Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1061,27 +1076,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/snowball/src/config.rs b/sdk/snowball/src/config.rs index 5978689d9b8c..f0cb361fa35b 100644 --- a/sdk/snowball/src/config.rs +++ b/sdk/snowball/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_snowball`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_snowball::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_snowball::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_snowball::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_snowball::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_snowball::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_snowball`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/snowball/src/config/endpoint.rs b/sdk/snowball/src/config/endpoint.rs index aab16b1e2a91..d5771f56e180 100644 --- a/sdk/snowball/src/config/endpoint.rs +++ b/sdk/snowball/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-2 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-3 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-south-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ap-southeast-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-2 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region eu-central-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-west-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-west-2 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-west-3 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region sa-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -849,7 +810,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region cn-northwest-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -891,7 +850,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -912,7 +870,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -933,7 +890,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -954,7 +910,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -975,7 +930,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -996,7 +950,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -1017,7 +970,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1038,7 +990,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1059,7 +1010,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1080,7 +1030,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1099,7 +1048,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1120,7 +1068,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1136,7 +1083,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1157,7 +1103,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1176,7 +1121,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1197,7 +1141,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1213,7 +1156,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1233,7 +1175,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1252,7 +1193,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1269,7 +1209,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1289,7 +1228,6 @@ mod test { /// Missing region #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1298,6 +1236,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Import/Export Snowball +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1334,27 +1336,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/snowdevicemanagement/src/config.rs b/sdk/snowdevicemanagement/src/config.rs index a7bb3271b35d..6e4e26e811ed 100644 --- a/sdk/snowdevicemanagement/src/config.rs +++ b/sdk/snowdevicemanagement/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_snowdevicemanagement`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_snowdevicemanagement::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_snowdevicemanagement::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_snowdevicemanagement::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_snowdevicemanagement::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_snowdevicemanagement::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_snowdevicemanagement`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/snowdevicemanagement/src/config/endpoint.rs b/sdk/snowdevicemanagement/src/config/endpoint.rs index 23a9dc894f72..cf859395cb8b 100644 --- a/sdk/snowdevicemanagement/src/config/endpoint.rs +++ b/sdk/snowdevicemanagement/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Snow Device Management +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sns/src/config.rs b/sdk/sns/src/config.rs index f9e04052ffd1..5fdbb57f46a7 100644 --- a/sdk/sns/src/config.rs +++ b/sdk/sns/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sns`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sns::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sns::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sns::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sns::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sns::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sns`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sns/src/config/endpoint.rs b/sdk/sns/src/config/endpoint.rs index cc48f20b021e..f65be9cba8bc 100644 --- a/sdk/sns/src/config/endpoint.rs +++ b/sdk/sns/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Simple Notification Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sqs/src/config.rs b/sdk/sqs/src/config.rs index 2e0c3d3a119f..c342f6da2a5f 100644 --- a/sdk/sqs/src/config.rs +++ b/sdk/sqs/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sqs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sqs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sqs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sqs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sqs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sqs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sqs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sqs/src/config/endpoint.rs b/sdk/sqs/src/config/endpoint.rs index 89abbe967908..22c83a42a1e5 100644 --- a/sdk/sqs/src/config/endpoint.rs +++ b/sdk/sqs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Simple Queue Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sqs/src/operation/change_message_visibility.rs b/sdk/sqs/src/operation/change_message_visibility.rs index fbc5446fe061..8b83920843f5 100644 --- a/sdk/sqs/src/operation/change_message_visibility.rs +++ b/sdk/sqs/src/operation/change_message_visibility.rs @@ -246,9 +246,7 @@ mod change_message_visibility_request_test { #[allow(unused_mut)] async fn sqs_set_visibility_zero_request() { let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); - let config_builder = crate::config::Config::builder() - .with_test_defaults() - .endpoint_resolver("https://example.com"); + let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com"); let mut config_builder = config_builder; config_builder.set_region(Some(crate::config::Region::new("us-east-1"))); diff --git a/sdk/ssm/src/config.rs b/sdk/ssm/src/config.rs index 9def4fdeb4a2..385908a33688 100644 --- a/sdk/ssm/src/config.rs +++ b/sdk/ssm/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssm`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ssm::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ssm::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ssm::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ssm::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ssm::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssm`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ssm/src/config/endpoint.rs b/sdk/ssm/src/config/endpoint.rs index 2c671d506f05..2e9f25f1327d 100644 --- a/sdk/ssm/src/config/endpoint.rs +++ b/sdk/ssm/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Simple Systems Manager (SSM) +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ssmcontacts/src/config.rs b/sdk/ssmcontacts/src/config.rs index 5fb29fbaf1e1..9ce05ddf5a25 100644 --- a/sdk/ssmcontacts/src/config.rs +++ b/sdk/ssmcontacts/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssmcontacts`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ssmcontacts::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ssmcontacts::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ssmcontacts::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ssmcontacts::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ssmcontacts::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssmcontacts`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ssmcontacts/src/config/endpoint.rs b/sdk/ssmcontacts/src/config/endpoint.rs index c4c47e4f91f1..74c03f22b7f4 100644 --- a/sdk/ssmcontacts/src/config/endpoint.rs +++ b/sdk/ssmcontacts/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Systems Manager Incident Manager Contacts +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ssmincidents/src/config.rs b/sdk/ssmincidents/src/config.rs index 15a561a3f31b..d36f064d35ef 100644 --- a/sdk/ssmincidents/src/config.rs +++ b/sdk/ssmincidents/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssmincidents`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ssmincidents::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ssmincidents::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ssmincidents::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ssmincidents::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ssmincidents::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssmincidents`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ssmincidents/src/config/endpoint.rs b/sdk/ssmincidents/src/config/endpoint.rs index cf80d9452039..be095099da1e 100644 --- a/sdk/ssmincidents/src/config/endpoint.rs +++ b/sdk/ssmincidents/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -595,7 +568,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -632,7 +603,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -672,7 +641,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -709,7 +676,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Systems Manager Incident Manager +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ssmsap/src/config.rs b/sdk/ssmsap/src/config.rs index 3291492112fe..9729b5811e93 100644 --- a/sdk/ssmsap/src/config.rs +++ b/sdk/ssmsap/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssmsap`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ssmsap::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ssmsap::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ssmsap::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ssmsap::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ssmsap::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssmsap`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ssmsap/src/config/endpoint.rs b/sdk/ssmsap/src/config/endpoint.rs index 17ad4434ec2f..abc8dd4f0d6f 100644 --- a/sdk/ssmsap/src/config/endpoint.rs +++ b/sdk/ssmsap/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Systems Manager for SAP +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sso/src/config.rs b/sdk/sso/src/config.rs index 0df6193da44d..dc857582f31f 100644 --- a/sdk/sso/src/config.rs +++ b/sdk/sso/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sso`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sso::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sso::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sso::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sso::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sso::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sso`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sso/src/config/endpoint.rs b/sdk/sso/src/config/endpoint.rs index 39d7f54e7fbc..670876fbd642 100644 --- a/sdk/sso/src/config/endpoint.rs +++ b/sdk/sso/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -834,7 +795,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -853,7 +813,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -870,7 +829,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -890,7 +848,6 @@ mod test { /// Missing region #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -899,6 +856,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Single Sign-On +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -935,27 +956,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ssoadmin/src/config.rs b/sdk/ssoadmin/src/config.rs index d0738e087f1e..ed8670ef20c3 100644 --- a/sdk/ssoadmin/src/config.rs +++ b/sdk/ssoadmin/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssoadmin`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ssoadmin::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ssoadmin::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ssoadmin::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ssoadmin::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ssoadmin::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssoadmin`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ssoadmin/src/config/endpoint.rs b/sdk/ssoadmin/src/config/endpoint.rs index 945e0a803c19..b70645722042 100644 --- a/sdk/ssoadmin/src/config/endpoint.rs +++ b/sdk/ssoadmin/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -758,7 +723,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -798,7 +761,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -835,7 +796,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -855,7 +815,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -874,7 +833,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -891,7 +849,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -911,7 +868,6 @@ mod test { /// Missing region #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -920,6 +876,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Single Sign-On Admin +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -956,27 +976,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/ssooidc/src/config.rs b/sdk/ssooidc/src/config.rs index 762f221c1cc5..09d776c93f35 100644 --- a/sdk/ssooidc/src/config.rs +++ b/sdk/ssooidc/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssooidc`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_ssooidc::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_ssooidc::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_ssooidc::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_ssooidc::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_ssooidc::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_ssooidc`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/ssooidc/src/config/endpoint.rs b/sdk/ssooidc/src/config/endpoint.rs index 833bfdfc5179..70faac6febb1 100644 --- a/sdk/ssooidc/src/config/endpoint.rs +++ b/sdk/ssooidc/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -834,7 +795,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -853,7 +813,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -870,7 +829,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -890,7 +848,6 @@ mod test { /// Missing region #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -899,6 +856,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS SSO OIDC +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -935,27 +956,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/storagegateway/src/config.rs b/sdk/storagegateway/src/config.rs index 363e828234a4..d1257061a765 100644 --- a/sdk/storagegateway/src/config.rs +++ b/sdk/storagegateway/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_storagegateway`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_storagegateway::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_storagegateway::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_storagegateway::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_storagegateway::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_storagegateway::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_storagegateway`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/storagegateway/src/config/endpoint.rs b/sdk/storagegateway/src/config/endpoint.rs index 6b70ab4eca28..22eb9c80f7d9 100644 --- a/sdk/storagegateway/src/config/endpoint.rs +++ b/sdk/storagegateway/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -828,7 +790,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Storage Gateway +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/sts/src/config.rs b/sdk/sts/src/config.rs index a48598c7104a..5bc65d8bd982 100644 --- a/sdk/sts/src/config.rs +++ b/sdk/sts/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sts`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_sts::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_sts::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_sts::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_sts::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_sts::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_sts`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/sts/src/config/endpoint.rs b/sdk/sts/src/config/endpoint.rs index 20b15ca40188..18660ec39df7 100644 --- a/sdk/sts/src/config/endpoint.rs +++ b/sdk/sts/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -229,7 +220,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -250,7 +240,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -271,7 +260,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -292,7 +280,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -313,7 +300,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -334,7 +320,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -355,7 +340,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -376,7 +360,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -397,7 +380,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -418,7 +400,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -439,7 +420,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -460,7 +440,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -481,7 +460,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -502,7 +480,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -523,7 +500,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -544,7 +520,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -565,7 +540,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -586,7 +560,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -607,7 +580,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -628,7 +600,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -649,7 +620,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -670,7 +640,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -691,7 +660,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -712,7 +680,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -733,7 +700,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -754,7 +720,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -775,7 +740,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -796,7 +760,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -817,7 +780,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -838,7 +800,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -859,7 +820,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -880,7 +840,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -901,7 +860,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -920,7 +878,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -941,7 +898,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -957,7 +913,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -978,7 +933,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -997,7 +951,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1018,7 +971,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1034,7 +986,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1054,7 +1005,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1073,7 +1023,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1090,7 +1039,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1110,7 +1058,6 @@ mod test { /// Missing region #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1121,7 +1068,6 @@ mod test { /// UseGlobalEndpoint with legacy region `ap-northeast-1` #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -1153,7 +1099,6 @@ mod test { /// UseGlobalEndpoint with legacy region `ap-south-1` #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -1185,7 +1130,6 @@ mod test { /// UseGlobalEndpoint with legacy region `ap-southeast-1` #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -1217,7 +1161,6 @@ mod test { /// UseGlobalEndpoint with legacy region `ap-southeast-2` #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -1249,7 +1192,6 @@ mod test { /// UseGlobalEndpoint with legacy region `aws-global` #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -1281,7 +1223,6 @@ mod test { /// UseGlobalEndpoint with legacy region `ca-central-1` #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -1313,7 +1254,6 @@ mod test { /// UseGlobalEndpoint with legacy region `eu-central-1` #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -1345,7 +1285,6 @@ mod test { /// UseGlobalEndpoint with legacy region `eu-north-1` #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -1377,7 +1316,6 @@ mod test { /// UseGlobalEndpoint with legacy region `eu-west-1` #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -1409,7 +1347,6 @@ mod test { /// UseGlobalEndpoint with legacy region `eu-west-2` #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -1441,7 +1378,6 @@ mod test { /// UseGlobalEndpoint with legacy region `eu-west-3` #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -1473,7 +1409,6 @@ mod test { /// UseGlobalEndpoint with legacy region `sa-east-1` #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -1505,7 +1440,6 @@ mod test { /// UseGlobalEndpoint with legacy region `us-east-1` #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1537,7 +1471,6 @@ mod test { /// UseGlobalEndpoint with legacy region `us-east-2` #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -1569,7 +1502,6 @@ mod test { /// UseGlobalEndpoint with legacy region `us-west-1` #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -1601,7 +1533,6 @@ mod test { /// UseGlobalEndpoint with legacy region `us-west-2` #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -1633,7 +1564,6 @@ mod test { /// UseGlobalEndpoint with Non-legacy region `us-east-3` #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-3".to_string()) .use_fips(false) @@ -1665,7 +1595,6 @@ mod test { /// UseGlobalEndpoint with legacy region and custom endpoint #[test] fn test_72() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -1686,7 +1615,6 @@ mod test { /// UseGlobalEndpoint with unset region and custom endpoint #[test] fn test_73() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1704,6 +1632,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Security Token Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1746,27 +1738,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/support/src/config.rs b/sdk/support/src/config.rs index fe6ddb28c744..589f4c96475d 100644 --- a/sdk/support/src/config.rs +++ b/sdk/support/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_support`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_support::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_support::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_support::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_support::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_support::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_support`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/support/src/config/endpoint.rs b/sdk/support/src/config/endpoint.rs index c8c014a8d774..065e59185d7c 100644 --- a/sdk/support/src/config/endpoint.rs +++ b/sdk/support/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -61,7 +60,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -82,7 +80,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -103,7 +100,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -134,7 +130,6 @@ mod test { /// For region aws-cn-global with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-cn-global".to_string()) .use_fips(false) @@ -165,7 +160,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -186,7 +180,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -207,7 +200,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -228,7 +220,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -259,7 +250,6 @@ mod test { /// For region aws-us-gov-global with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-us-gov-global".to_string()) .use_fips(false) @@ -290,7 +280,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -311,7 +300,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -332,7 +320,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -353,7 +340,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -384,7 +370,6 @@ mod test { /// For region aws-iso-global with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-iso-global".to_string()) .use_fips(false) @@ -415,7 +400,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -434,7 +418,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -455,7 +438,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -471,7 +453,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -502,7 +483,6 @@ mod test { /// For region aws-iso-b-global with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-iso-b-global".to_string()) .use_fips(false) @@ -533,7 +513,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -552,7 +531,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -573,7 +551,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -589,7 +566,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -620,7 +596,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -640,7 +615,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -659,7 +633,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -676,7 +649,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -696,7 +668,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -705,6 +676,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Support +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -741,27 +776,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/supportapp/src/config.rs b/sdk/supportapp/src/config.rs index 8f6d563b94fb..dffea44737f0 100644 --- a/sdk/supportapp/src/config.rs +++ b/sdk/supportapp/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_supportapp`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_supportapp::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_supportapp::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_supportapp::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_supportapp::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_supportapp::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_supportapp`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/supportapp/src/config/endpoint.rs b/sdk/supportapp/src/config/endpoint.rs index c32f7018674b..abae7f1fb614 100644 --- a/sdk/supportapp/src/config/endpoint.rs +++ b/sdk/supportapp/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Support App +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/swf/src/config.rs b/sdk/swf/src/config.rs index d4e5928c260d..a3037deca391 100644 --- a/sdk/swf/src/config.rs +++ b/sdk/swf/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_swf`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_swf::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_swf::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_swf::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_swf::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_swf::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_swf`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/swf/src/config/endpoint.rs b/sdk/swf/src/config/endpoint.rs index 023e668c0587..9e9d05ea351f 100644 --- a/sdk/swf/src/config/endpoint.rs +++ b/sdk/swf/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -910,7 +868,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -947,7 +903,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -987,7 +941,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1003,7 +956,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1023,7 +975,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1042,7 +993,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1059,7 +1009,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1079,7 +1028,6 @@ mod test { /// Missing region #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1088,6 +1036,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Simple Workflow Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1124,27 +1136,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/synthetics/src/config.rs b/sdk/synthetics/src/config.rs index 0bd018df6f30..d9d375d00b1b 100644 --- a/sdk/synthetics/src/config.rs +++ b/sdk/synthetics/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_synthetics`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_synthetics::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_synthetics::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_synthetics::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_synthetics::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_synthetics::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_synthetics`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/synthetics/src/config/endpoint.rs b/sdk/synthetics/src/config/endpoint.rs index 6ef26f75675e..6e4573c3e359 100644 --- a/sdk/synthetics/src/config/endpoint.rs +++ b/sdk/synthetics/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -849,7 +810,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -889,7 +848,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -926,7 +883,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -966,7 +921,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to Synthetics +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/textract/src/config.rs b/sdk/textract/src/config.rs index 4e146c06e4a6..b4d07b2e01e3 100644 --- a/sdk/textract/src/config.rs +++ b/sdk/textract/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_textract`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_textract::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_textract::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_textract::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_textract::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_textract::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_textract`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/textract/src/config/endpoint.rs b/sdk/textract/src/config/endpoint.rs index 2df3836c5e2f..9e79e6929ed4 100644 --- a/sdk/textract/src/config/endpoint.rs +++ b/sdk/textract/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -658,7 +628,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -679,7 +648,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -695,7 +663,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -716,7 +683,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -735,7 +701,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -772,7 +736,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -813,7 +775,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -832,7 +793,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -849,7 +809,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -869,7 +828,6 @@ mod test { /// Missing region #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -878,6 +836,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Textract +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -914,27 +936,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/timestreamquery/src/client.rs b/sdk/timestreamquery/src/client.rs index b554e258ea07..335cb48dd8a0 100644 --- a/sdk/timestreamquery/src/client.rs +++ b/sdk/timestreamquery/src/client.rs @@ -1,12 +1,8 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. async fn resolve_endpoint( client: &crate::Client, -) -> Result<(::aws_smithy_types::endpoint::Endpoint, ::std::time::SystemTime), ::aws_smithy_http::endpoint::ResolveEndpointError> { - let describe_endpoints = client - .describe_endpoints() - .send() - .await - .map_err(|e| ::aws_smithy_http::endpoint::ResolveEndpointError::from_source("failed to call describe_endpoints", e))?; +) -> Result<(::aws_smithy_types::endpoint::Endpoint, ::std::time::SystemTime), ::aws_smithy_runtime_api::box_error::BoxError> { + let describe_endpoints = client.describe_endpoints().send().await?; let endpoint = describe_endpoints.endpoints().get(0).unwrap(); let expiry = client.config().time_source().expect("checked when ep discovery was enabled").now() + ::std::time::Duration::from_secs(endpoint.cache_period_in_minutes() as u64 * 60); @@ -24,7 +20,7 @@ impl Client { /// This method MUST be called to construct a working client. pub async fn with_endpoint_discovery_enabled( self, - ) -> ::std::result::Result<(Self, crate::endpoint_discovery::ReloadEndpoint), ::aws_smithy_http::endpoint::ResolveEndpointError> { + ) -> ::std::result::Result<(Self, crate::endpoint_discovery::ReloadEndpoint), ::aws_smithy_runtime_api::box_error::BoxError> { let handle = self.handle.clone(); // The original client without endpoint discover gets moved into the endpoint discovery @@ -46,13 +42,11 @@ impl Client { ) .await?; - let client_with_discovery = crate::Client::from_conf( - handle - .conf - .to_builder() - .endpoint_resolver(::aws_smithy_http::endpoint::SharedEndpointResolver::new(resolver)) - .build(), - ); + use ::aws_smithy_runtime_api::shared::IntoShared; + let mut conf = handle.conf.to_builder(); + conf.set_endpoint_resolver(Some(resolver.into_shared())); + + let client_with_discovery = crate::Client::from_conf(conf.build()); Ok((client_with_discovery, reloader)) } } diff --git a/sdk/timestreamquery/src/config.rs b/sdk/timestreamquery/src/config.rs index 21f8a73e73c7..d381c71bdd67 100644 --- a/sdk/timestreamquery/src/config.rs +++ b/sdk/timestreamquery/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_timestreamquery`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_timestreamquery::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_timestreamquery::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_timestreamquery::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_timestreamquery::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_timestreamquery::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_timestreamquery`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/timestreamquery/src/config/endpoint.rs b/sdk/timestreamquery/src/config/endpoint.rs index c0087b20ca9f..8567b62c2b32 100644 --- a/sdk/timestreamquery/src/config/endpoint.rs +++ b/sdk/timestreamquery/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Timestream Query +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/timestreamquery/src/endpoint_discovery.rs b/sdk/timestreamquery/src/endpoint_discovery.rs index f9a92ae1ce74..d55f96952f24 100644 --- a/sdk/timestreamquery/src/endpoint_discovery.rs +++ b/sdk/timestreamquery/src/endpoint_discovery.rs @@ -9,7 +9,8 @@ use aws_smithy_async::future::BoxFuture; use aws_smithy_async::rt::sleep::{AsyncSleep, SharedAsyncSleep}; use aws_smithy_async::time::SharedTimeSource; -use aws_smithy_http::endpoint::{ResolveEndpoint, ResolveEndpointError}; +use aws_smithy_runtime_api::box_error::BoxError; +use aws_smithy_runtime_api::client::endpoint::{EndpointFuture, EndpointResolverParams, ResolveEndpoint}; use aws_smithy_types::endpoint::Endpoint; use std::fmt::{Debug, Formatter}; use std::future::Future; @@ -21,9 +22,9 @@ use tokio::sync::oneshot::{Receiver, Sender}; /// Endpoint reloader #[must_use] pub struct ReloadEndpoint { - loader: Box BoxFuture<'static, (Endpoint, SystemTime), ResolveEndpointError> + Send + Sync>, + loader: Box BoxFuture<'static, (Endpoint, SystemTime), BoxError> + Send + Sync>, endpoint: Arc>>, - error: Arc>>, + error: Arc>>, rx: Receiver<()>, sleep: SharedAsyncSleep, time: SharedTimeSource, @@ -72,14 +73,14 @@ impl ReloadEndpoint { #[derive(Debug, Clone)] pub(crate) struct EndpointCache { - error: Arc>>, + error: Arc>>, endpoint: Arc>>, // When the sender is dropped, this allows the reload loop to stop _drop_guard: Arc>, } -impl ResolveEndpoint for EndpointCache { - fn resolve_endpoint(&self, _params: &T) -> aws_smithy_http::endpoint::Result { +impl ResolveEndpoint for EndpointCache { + fn resolve_endpoint<'a>(&'a self, _params: &'a EndpointResolverParams) -> EndpointFuture<'a> { self.resolve_endpoint() } } @@ -104,9 +105,9 @@ pub(crate) async fn create_cache( loader_fn: impl Fn() -> F + Send + Sync + 'static, sleep: SharedAsyncSleep, time: SharedTimeSource, -) -> Result<(EndpointCache, ReloadEndpoint), ResolveEndpointError> +) -> Result<(EndpointCache, ReloadEndpoint), BoxError> where - F: Future> + Send + 'static, + F: Future> + Send + 'static, { let error_holder = Arc::new(Mutex::new(None)); let endpoint_holder = Arc::new(Mutex::new(None)); @@ -128,20 +129,18 @@ where reloader.reload_once().await; // if we didn't successfully get an endpoint, bail out so the client knows // configuration failed to work - cache.resolve_endpoint()?; + cache.resolve_endpoint().await?; Ok((cache, reloader)) } impl EndpointCache { - fn resolve_endpoint(&self) -> aws_smithy_http::endpoint::Result { + fn resolve_endpoint(&self) -> EndpointFuture<'_> { tracing::trace!("resolving endpoint from endpoint discovery cache"); - self.endpoint.lock().unwrap().as_ref().map(|e| e.endpoint.clone()).ok_or_else(|| { - self.error - .lock() - .unwrap() - .take() - .unwrap_or_else(|| ResolveEndpointError::message("no endpoint loaded")) - }) + let ep = self.endpoint.lock().unwrap().as_ref().map(|e| e.endpoint.clone()).ok_or_else(|| { + let error: Option = self.error.lock().unwrap().take(); + error.unwrap_or_else(|| "Failed to resolve endpoint".into()) + }); + EndpointFuture::ready(ep) } } @@ -190,13 +189,13 @@ mod test { ) .await .expect("returns an endpoint"); - assert_eq!(cache.resolve_endpoint().expect("ok").url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.expect("ok").url(), "http://foo.com/1"); // 120 second buffer reloader.reload_increment(expiry - Duration::from_secs(240)).await; - assert_eq!(cache.resolve_endpoint().expect("ok").url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.expect("ok").url(), "http://foo.com/1"); reloader.reload_increment(expiry).await; - assert_eq!(cache.resolve_endpoint().expect("ok").url(), "http://foo.com/2"); + assert_eq!(cache.resolve_endpoint().await.expect("ok").url(), "http://foo.com/2"); } #[tokio::test] @@ -221,18 +220,18 @@ mod test { // expiry occurs after 2 sleeps // t = 0 assert_eq!(gate.expect_sleep().await.duration(), Duration::from_secs(60)); - assert_eq!(cache.resolve_endpoint().unwrap().url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.unwrap().url(), "http://foo.com/1"); // t = 60 let sleep = gate.expect_sleep().await; // we're still holding the drop guard, so we haven't expired yet. - assert_eq!(cache.resolve_endpoint().unwrap().url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.unwrap().url(), "http://foo.com/1"); assert_eq!(sleep.duration(), Duration::from_secs(60)); sleep.allow_progress(); // t = 120 let sleep = gate.expect_sleep().await; - assert_eq!(cache.resolve_endpoint().unwrap().url(), "http://foo.com/2"); + assert_eq!(cache.resolve_endpoint().await.unwrap().url(), "http://foo.com/2"); sleep.allow_progress(); let sleep = gate.expect_sleep().await; diff --git a/sdk/timestreamwrite/src/client.rs b/sdk/timestreamwrite/src/client.rs index 40b0c3b1b389..fca40583b561 100644 --- a/sdk/timestreamwrite/src/client.rs +++ b/sdk/timestreamwrite/src/client.rs @@ -1,12 +1,8 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. async fn resolve_endpoint( client: &crate::Client, -) -> Result<(::aws_smithy_types::endpoint::Endpoint, ::std::time::SystemTime), ::aws_smithy_http::endpoint::ResolveEndpointError> { - let describe_endpoints = client - .describe_endpoints() - .send() - .await - .map_err(|e| ::aws_smithy_http::endpoint::ResolveEndpointError::from_source("failed to call describe_endpoints", e))?; +) -> Result<(::aws_smithy_types::endpoint::Endpoint, ::std::time::SystemTime), ::aws_smithy_runtime_api::box_error::BoxError> { + let describe_endpoints = client.describe_endpoints().send().await?; let endpoint = describe_endpoints.endpoints().get(0).unwrap(); let expiry = client.config().time_source().expect("checked when ep discovery was enabled").now() + ::std::time::Duration::from_secs(endpoint.cache_period_in_minutes() as u64 * 60); @@ -24,7 +20,7 @@ impl Client { /// This method MUST be called to construct a working client. pub async fn with_endpoint_discovery_enabled( self, - ) -> ::std::result::Result<(Self, crate::endpoint_discovery::ReloadEndpoint), ::aws_smithy_http::endpoint::ResolveEndpointError> { + ) -> ::std::result::Result<(Self, crate::endpoint_discovery::ReloadEndpoint), ::aws_smithy_runtime_api::box_error::BoxError> { let handle = self.handle.clone(); // The original client without endpoint discover gets moved into the endpoint discovery @@ -46,13 +42,11 @@ impl Client { ) .await?; - let client_with_discovery = crate::Client::from_conf( - handle - .conf - .to_builder() - .endpoint_resolver(::aws_smithy_http::endpoint::SharedEndpointResolver::new(resolver)) - .build(), - ); + use ::aws_smithy_runtime_api::shared::IntoShared; + let mut conf = handle.conf.to_builder(); + conf.set_endpoint_resolver(Some(resolver.into_shared())); + + let client_with_discovery = crate::Client::from_conf(conf.build()); Ok((client_with_discovery, reloader)) } } diff --git a/sdk/timestreamwrite/src/config.rs b/sdk/timestreamwrite/src/config.rs index 590273e1bdf8..a6b612d66db0 100644 --- a/sdk/timestreamwrite/src/config.rs +++ b/sdk/timestreamwrite/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_timestreamwrite`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_timestreamwrite::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_timestreamwrite::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_timestreamwrite::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_timestreamwrite::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_timestreamwrite::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_timestreamwrite`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/timestreamwrite/src/config/endpoint.rs b/sdk/timestreamwrite/src/config/endpoint.rs index 9f38ae38db3a..a954e700632e 100644 --- a/sdk/timestreamwrite/src/config/endpoint.rs +++ b/sdk/timestreamwrite/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Timestream Write +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/timestreamwrite/src/endpoint_discovery.rs b/sdk/timestreamwrite/src/endpoint_discovery.rs index f9a92ae1ce74..d55f96952f24 100644 --- a/sdk/timestreamwrite/src/endpoint_discovery.rs +++ b/sdk/timestreamwrite/src/endpoint_discovery.rs @@ -9,7 +9,8 @@ use aws_smithy_async::future::BoxFuture; use aws_smithy_async::rt::sleep::{AsyncSleep, SharedAsyncSleep}; use aws_smithy_async::time::SharedTimeSource; -use aws_smithy_http::endpoint::{ResolveEndpoint, ResolveEndpointError}; +use aws_smithy_runtime_api::box_error::BoxError; +use aws_smithy_runtime_api::client::endpoint::{EndpointFuture, EndpointResolverParams, ResolveEndpoint}; use aws_smithy_types::endpoint::Endpoint; use std::fmt::{Debug, Formatter}; use std::future::Future; @@ -21,9 +22,9 @@ use tokio::sync::oneshot::{Receiver, Sender}; /// Endpoint reloader #[must_use] pub struct ReloadEndpoint { - loader: Box BoxFuture<'static, (Endpoint, SystemTime), ResolveEndpointError> + Send + Sync>, + loader: Box BoxFuture<'static, (Endpoint, SystemTime), BoxError> + Send + Sync>, endpoint: Arc>>, - error: Arc>>, + error: Arc>>, rx: Receiver<()>, sleep: SharedAsyncSleep, time: SharedTimeSource, @@ -72,14 +73,14 @@ impl ReloadEndpoint { #[derive(Debug, Clone)] pub(crate) struct EndpointCache { - error: Arc>>, + error: Arc>>, endpoint: Arc>>, // When the sender is dropped, this allows the reload loop to stop _drop_guard: Arc>, } -impl ResolveEndpoint for EndpointCache { - fn resolve_endpoint(&self, _params: &T) -> aws_smithy_http::endpoint::Result { +impl ResolveEndpoint for EndpointCache { + fn resolve_endpoint<'a>(&'a self, _params: &'a EndpointResolverParams) -> EndpointFuture<'a> { self.resolve_endpoint() } } @@ -104,9 +105,9 @@ pub(crate) async fn create_cache( loader_fn: impl Fn() -> F + Send + Sync + 'static, sleep: SharedAsyncSleep, time: SharedTimeSource, -) -> Result<(EndpointCache, ReloadEndpoint), ResolveEndpointError> +) -> Result<(EndpointCache, ReloadEndpoint), BoxError> where - F: Future> + Send + 'static, + F: Future> + Send + 'static, { let error_holder = Arc::new(Mutex::new(None)); let endpoint_holder = Arc::new(Mutex::new(None)); @@ -128,20 +129,18 @@ where reloader.reload_once().await; // if we didn't successfully get an endpoint, bail out so the client knows // configuration failed to work - cache.resolve_endpoint()?; + cache.resolve_endpoint().await?; Ok((cache, reloader)) } impl EndpointCache { - fn resolve_endpoint(&self) -> aws_smithy_http::endpoint::Result { + fn resolve_endpoint(&self) -> EndpointFuture<'_> { tracing::trace!("resolving endpoint from endpoint discovery cache"); - self.endpoint.lock().unwrap().as_ref().map(|e| e.endpoint.clone()).ok_or_else(|| { - self.error - .lock() - .unwrap() - .take() - .unwrap_or_else(|| ResolveEndpointError::message("no endpoint loaded")) - }) + let ep = self.endpoint.lock().unwrap().as_ref().map(|e| e.endpoint.clone()).ok_or_else(|| { + let error: Option = self.error.lock().unwrap().take(); + error.unwrap_or_else(|| "Failed to resolve endpoint".into()) + }); + EndpointFuture::ready(ep) } } @@ -190,13 +189,13 @@ mod test { ) .await .expect("returns an endpoint"); - assert_eq!(cache.resolve_endpoint().expect("ok").url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.expect("ok").url(), "http://foo.com/1"); // 120 second buffer reloader.reload_increment(expiry - Duration::from_secs(240)).await; - assert_eq!(cache.resolve_endpoint().expect("ok").url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.expect("ok").url(), "http://foo.com/1"); reloader.reload_increment(expiry).await; - assert_eq!(cache.resolve_endpoint().expect("ok").url(), "http://foo.com/2"); + assert_eq!(cache.resolve_endpoint().await.expect("ok").url(), "http://foo.com/2"); } #[tokio::test] @@ -221,18 +220,18 @@ mod test { // expiry occurs after 2 sleeps // t = 0 assert_eq!(gate.expect_sleep().await.duration(), Duration::from_secs(60)); - assert_eq!(cache.resolve_endpoint().unwrap().url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.unwrap().url(), "http://foo.com/1"); // t = 60 let sleep = gate.expect_sleep().await; // we're still holding the drop guard, so we haven't expired yet. - assert_eq!(cache.resolve_endpoint().unwrap().url(), "http://foo.com/1"); + assert_eq!(cache.resolve_endpoint().await.unwrap().url(), "http://foo.com/1"); assert_eq!(sleep.duration(), Duration::from_secs(60)); sleep.allow_progress(); // t = 120 let sleep = gate.expect_sleep().await; - assert_eq!(cache.resolve_endpoint().unwrap().url(), "http://foo.com/2"); + assert_eq!(cache.resolve_endpoint().await.unwrap().url(), "http://foo.com/2"); sleep.allow_progress(); let sleep = gate.expect_sleep().await; diff --git a/sdk/tnb/src/config.rs b/sdk/tnb/src/config.rs index 73431d735b0b..ec5cc018d03f 100644 --- a/sdk/tnb/src/config.rs +++ b/sdk/tnb/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_tnb`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_tnb::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_tnb::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_tnb::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_tnb::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_tnb::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_tnb`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/tnb/src/config/endpoint.rs b/sdk/tnb/src/config/endpoint.rs index 2eea9cbf0461..afae7566be2a 100644 --- a/sdk/tnb/src/config/endpoint.rs +++ b/sdk/tnb/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Telco Network Builder +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/transcribe/src/config.rs b/sdk/transcribe/src/config.rs index ba7932d7c307..28f9d5b7c82a 100644 --- a/sdk/transcribe/src/config.rs +++ b/sdk/transcribe/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_transcribe`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_transcribe::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_transcribe::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_transcribe::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_transcribe::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_transcribe::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_transcribe`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/transcribe/src/config/endpoint.rs b/sdk/transcribe/src/config/endpoint.rs index 26867e9b1695..c9045e35558b 100644 --- a/sdk/transcribe/src/config/endpoint.rs +++ b/sdk/transcribe/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -807,7 +770,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -826,7 +788,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -863,7 +823,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -882,7 +841,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -903,7 +861,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -919,7 +876,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -940,7 +896,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -960,7 +915,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -979,7 +933,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -996,7 +949,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1016,7 +968,6 @@ mod test { /// Missing region #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1025,6 +976,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Transcribe Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1061,27 +1076,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/transcribestreaming/Cargo.toml b/sdk/transcribestreaming/Cargo.toml index f2c1fb180747..7fbea5d5636f 100644 --- a/sdk/transcribestreaming/Cargo.toml +++ b/sdk/transcribestreaming/Cargo.toml @@ -102,10 +102,6 @@ path = "../aws-smithy-async" features = ["test-util"] version = "0.56.1" -[dev-dependencies.aws-smithy-http] -path = "../aws-smithy-http" -version = "0.56.1" - [dev-dependencies.aws-smithy-protocol-test] path = "../aws-smithy-protocol-test" version = "0.56.1" diff --git a/sdk/transcribestreaming/src/config.rs b/sdk/transcribestreaming/src/config.rs index fb6e00ea9112..a96e3ad8ca40 100644 --- a/sdk/transcribestreaming/src/config.rs +++ b/sdk/transcribestreaming/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_transcribestreaming`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_transcribestreaming::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_transcribestreaming::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_transcribestreaming::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_transcribestreaming::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_transcribestreaming::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_transcribestreaming`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/transcribestreaming/src/config/endpoint.rs b/sdk/transcribestreaming/src/config/endpoint.rs index 446cc3cbd6dc..49ea7cd79e8e 100644 --- a/sdk/transcribestreaming/src/config/endpoint.rs +++ b/sdk/transcribestreaming/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -553,7 +528,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -574,7 +548,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -590,7 +563,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -609,7 +581,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -630,7 +601,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -646,7 +616,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -667,7 +636,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -687,7 +655,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -706,7 +673,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -723,7 +689,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -743,7 +708,6 @@ mod test { /// Missing region #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -752,6 +716,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Transcribe Streaming Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -788,27 +816,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/transfer/src/config.rs b/sdk/transfer/src/config.rs index a8073038bb6c..3d791cf24053 100644 --- a/sdk/transfer/src/config.rs +++ b/sdk/transfer/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_transfer`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_transfer::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_transfer::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_transfer::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_transfer::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_transfer::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_transfer`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/transfer/src/config/endpoint.rs b/sdk/transfer/src/config/endpoint.rs index 97cf6f4c684e..ef4be0de3c5c 100644 --- a/sdk/transfer/src/config/endpoint.rs +++ b/sdk/transfer/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Transfer Family +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/translate/src/config.rs b/sdk/translate/src/config.rs index 9be3e1c0b99e..0edc4a9e17de 100644 --- a/sdk/translate/src/config.rs +++ b/sdk/translate/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_translate`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_translate::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_translate::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_translate::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_translate::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_translate::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_translate`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/translate/src/config/endpoint.rs b/sdk/translate/src/config/endpoint.rs index 81ac6c168034..e38cced2c48e 100644 --- a/sdk/translate/src/config/endpoint.rs +++ b/sdk/translate/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -618,7 +590,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -681,7 +650,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -700,7 +668,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -721,7 +688,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -737,7 +703,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -756,7 +721,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -777,7 +741,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -793,7 +756,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -814,7 +776,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -834,7 +795,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -853,7 +813,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -870,7 +829,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -890,7 +848,6 @@ mod test { /// Missing region #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -899,6 +856,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Translate +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -935,27 +956,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/verifiedpermissions/src/config.rs b/sdk/verifiedpermissions/src/config.rs index c6e7e607b82f..841ec35858e5 100644 --- a/sdk/verifiedpermissions/src/config.rs +++ b/sdk/verifiedpermissions/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_verifiedpermissions`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_verifiedpermissions::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_verifiedpermissions::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_verifiedpermissions::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_verifiedpermissions::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_verifiedpermissions::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_verifiedpermissions`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/verifiedpermissions/src/config/endpoint.rs b/sdk/verifiedpermissions/src/config/endpoint.rs index 2afcc6c7504d..d51f740f1620 100644 --- a/sdk/verifiedpermissions/src/config/endpoint.rs +++ b/sdk/verifiedpermissions/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Verified Permissions +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/voiceid/src/config.rs b/sdk/voiceid/src/config.rs index 47d25851444b..add2fd9b3c65 100644 --- a/sdk/voiceid/src/config.rs +++ b/sdk/voiceid/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_voiceid`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_voiceid::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_voiceid::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_voiceid::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_voiceid::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_voiceid::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_voiceid`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/voiceid/src/config/endpoint.rs b/sdk/voiceid/src/config/endpoint.rs index b26962504982..45f7a4f3b82c 100644 --- a/sdk/voiceid/src/config/endpoint.rs +++ b/sdk/voiceid/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Voice ID +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/vpclattice/src/config.rs b/sdk/vpclattice/src/config.rs index b66bb221110e..6460a59e30d1 100644 --- a/sdk/vpclattice/src/config.rs +++ b/sdk/vpclattice/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_vpclattice`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_vpclattice::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_vpclattice::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_vpclattice::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_vpclattice::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_vpclattice::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_vpclattice`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/vpclattice/src/config/endpoint.rs b/sdk/vpclattice/src/config/endpoint.rs index b471036d3825..20ad343c734e 100644 --- a/sdk/vpclattice/src/config/endpoint.rs +++ b/sdk/vpclattice/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon VPC Lattice +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/waf/src/config.rs b/sdk/waf/src/config.rs index aced559204db..8b3a8d193b87 100644 --- a/sdk/waf/src/config.rs +++ b/sdk/waf/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_waf`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_waf::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_waf::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_waf::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_waf::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_waf::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_waf`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/waf/src/config/endpoint.rs b/sdk/waf/src/config/endpoint.rs index 4f08f3fa79b0..a0e5fac722ea 100644 --- a/sdk/waf/src/config/endpoint.rs +++ b/sdk/waf/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region aws-global with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(false) @@ -40,7 +40,6 @@ mod test { /// For region aws-global with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("aws-global".to_string()) .use_fips(true) @@ -71,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -92,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -123,7 +120,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -144,7 +140,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -175,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -196,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -217,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -238,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -259,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -280,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -301,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -322,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -343,7 +330,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -362,7 +348,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -383,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -399,7 +383,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -420,7 +403,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -439,7 +421,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -460,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -476,7 +456,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -497,7 +476,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -517,7 +495,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -536,7 +513,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -553,7 +529,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -573,7 +548,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -582,6 +556,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS WAF +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -618,27 +656,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/wafregional/src/config.rs b/sdk/wafregional/src/config.rs index 7dfb14c7771a..bca82f20f019 100644 --- a/sdk/wafregional/src/config.rs +++ b/sdk/wafregional/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wafregional`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_wafregional::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_wafregional::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_wafregional::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_wafregional::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_wafregional::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wafregional`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/wafregional/src/config/endpoint.rs b/sdk/wafregional/src/config/endpoint.rs index 695e105dfbb6..8d3d55107d96 100644 --- a/sdk/wafregional/src/config/endpoint.rs +++ b/sdk/wafregional/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region af-south-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-northeast-3 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ap-south-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region ap-southeast-2 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region ap-southeast-3 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-central-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-south-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region eu-west-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region eu-west-2 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region eu-west-3 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region me-south-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region sa-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -849,7 +810,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -891,7 +850,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -912,7 +870,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -933,7 +890,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +910,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -975,7 +930,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -996,7 +950,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1017,7 +970,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -1038,7 +990,6 @@ mod test { /// For region cn-northwest-1 with FIPS enabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -1059,7 +1010,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1080,7 +1030,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -1101,7 +1050,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1122,7 +1070,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1143,7 +1090,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1164,7 +1110,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -1185,7 +1130,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1206,7 +1150,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1227,7 +1170,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1246,7 +1188,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1267,7 +1208,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1283,7 +1223,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1304,7 +1243,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1323,7 +1261,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1344,7 +1281,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1360,7 +1296,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1381,7 +1316,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1401,7 +1335,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1420,7 +1353,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1437,7 +1369,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1457,7 +1388,6 @@ mod test { /// Missing region #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1466,6 +1396,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS WAF Regional +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1502,27 +1496,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/wafv2/src/config.rs b/sdk/wafv2/src/config.rs index 5888fee2ee1c..d84f301b7118 100644 --- a/sdk/wafv2/src/config.rs +++ b/sdk/wafv2/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wafv2`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_wafv2::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_wafv2::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_wafv2::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_wafv2::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_wafv2::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wafv2`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/wafv2/src/config/endpoint.rs b/sdk/wafv2/src/config/endpoint.rs index 333f6675c8a9..828700133cc7 100644 --- a/sdk/wafv2/src/config/endpoint.rs +++ b/sdk/wafv2/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region af-south-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-east-1 with FIPS enabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-northeast-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-northeast-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ap-northeast-3 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region ap-south-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region ap-southeast-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region ap-southeast-2 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region ap-southeast-3 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region ca-central-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region eu-central-1 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region eu-north-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region eu-south-1 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region eu-west-1 with FIPS enabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(true) @@ -597,7 +570,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region eu-west-2 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(true) @@ -639,7 +610,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -660,7 +630,6 @@ mod test { /// For region eu-west-3 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region me-south-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(true) @@ -723,7 +690,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -744,7 +710,6 @@ mod test { /// For region sa-east-1 with FIPS enabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(true) @@ -765,7 +730,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -786,7 +750,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -849,7 +810,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -870,7 +830,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -891,7 +850,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -912,7 +870,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -933,7 +890,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -954,7 +910,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -975,7 +930,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -996,7 +950,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1017,7 +970,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -1038,7 +990,6 @@ mod test { /// For region cn-northwest-1 with FIPS enabled and DualStack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(true) @@ -1059,7 +1010,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -1080,7 +1030,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -1101,7 +1050,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_53() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1122,7 +1070,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_54() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1143,7 +1090,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_55() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -1164,7 +1110,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_56() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -1185,7 +1130,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_57() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -1206,7 +1150,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_58() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -1227,7 +1170,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_59() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1246,7 +1188,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_60() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -1267,7 +1208,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_61() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1283,7 +1223,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_62() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -1304,7 +1243,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_63() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1323,7 +1261,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_64() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -1344,7 +1281,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_65() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1360,7 +1296,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_66() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -1381,7 +1316,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_67() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1401,7 +1335,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_68() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1420,7 +1353,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_69() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1437,7 +1369,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_70() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1457,7 +1388,6 @@ mod test { /// Missing region #[test] fn test_71() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1466,6 +1396,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS WAFV2 +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1502,27 +1496,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/wellarchitected/src/config.rs b/sdk/wellarchitected/src/config.rs index c029bed9b89d..18c8536140cd 100644 --- a/sdk/wellarchitected/src/config.rs +++ b/sdk/wellarchitected/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wellarchitected`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_wellarchitected::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_wellarchitected::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_wellarchitected::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_wellarchitected::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_wellarchitected::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wellarchitected`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/wellarchitected/src/config/endpoint.rs b/sdk/wellarchitected/src/config/endpoint.rs index 2e405d3090bd..082db504cb6f 100644 --- a/sdk/wellarchitected/src/config/endpoint.rs +++ b/sdk/wellarchitected/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -513,7 +490,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -658,7 +628,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -695,7 +663,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -735,7 +701,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -751,7 +716,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -772,7 +736,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -792,7 +755,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -811,7 +773,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -828,7 +789,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -848,7 +808,6 @@ mod test { /// Missing region #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -857,6 +816,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS Well-Architected Tool +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -893,27 +916,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/wisdom/src/config.rs b/sdk/wisdom/src/config.rs index 5874ef64108e..39c582fa053f 100644 --- a/sdk/wisdom/src/config.rs +++ b/sdk/wisdom/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wisdom`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_wisdom::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_wisdom::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_wisdom::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_wisdom::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_wisdom::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_wisdom`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/wisdom/src/config/endpoint.rs b/sdk/wisdom/src/config/endpoint.rs index ff3a2cc1f1d9..2f6bca26c42d 100644 --- a/sdk/wisdom/src/config/endpoint.rs +++ b/sdk/wisdom/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -385,7 +368,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -422,7 +403,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -462,7 +441,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -499,7 +476,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -540,7 +515,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -559,7 +533,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +549,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -596,7 +568,6 @@ mod test { /// Missing region #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -605,6 +576,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon Connect Wisdom Service +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -641,27 +676,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/workdocs/src/config.rs b/sdk/workdocs/src/config.rs index f347bf4f0a9a..b8e8e2ccd8d6 100644 --- a/sdk/workdocs/src/config.rs +++ b/sdk/workdocs/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workdocs`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_workdocs::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_workdocs::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_workdocs::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_workdocs::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_workdocs::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workdocs`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/workdocs/src/config/endpoint.rs b/sdk/workdocs/src/config/endpoint.rs index a090d160b70d..1783bc9f1278 100644 --- a/sdk/workdocs/src/config/endpoint.rs +++ b/sdk/workdocs/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -345,7 +330,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -406,7 +388,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -427,7 +408,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -443,7 +423,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -464,7 +443,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -483,7 +461,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -504,7 +481,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -520,7 +496,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -541,7 +516,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -561,7 +535,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -580,7 +553,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -597,7 +569,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -617,7 +588,6 @@ mod test { /// Missing region #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -626,6 +596,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon WorkDocs +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -662,27 +696,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/worklink/src/config.rs b/sdk/worklink/src/config.rs index 7eeebbfde5ad..96c5949ade97 100644 --- a/sdk/worklink/src/config.rs +++ b/sdk/worklink/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_worklink`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_worklink::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_worklink::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_worklink::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_worklink::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_worklink::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_worklink`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/worklink/src/config/endpoint.rs b/sdk/worklink/src/config/endpoint.rs index 6db5d1979639..4efc544a8768 100644 --- a/sdk/worklink/src/config/endpoint.rs +++ b/sdk/worklink/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon WorkLink +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/workmail/src/config.rs b/sdk/workmail/src/config.rs index 9192bd7e642e..b95c72e35ea4 100644 --- a/sdk/workmail/src/config.rs +++ b/sdk/workmail/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workmail`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_workmail::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_workmail::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_workmail::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_workmail::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_workmail::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workmail`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/workmail/src/config/endpoint.rs b/sdk/workmail/src/config/endpoint.rs index d94e81cd4c87..204466c53768 100644 --- a/sdk/workmail/src/config/endpoint.rs +++ b/sdk/workmail/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon WorkMail +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/workmailmessageflow/src/config.rs b/sdk/workmailmessageflow/src/config.rs index 72bab380539e..aaf8f780261e 100644 --- a/sdk/workmailmessageflow/src/config.rs +++ b/sdk/workmailmessageflow/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workmailmessageflow`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_workmailmessageflow::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_workmailmessageflow::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_workmailmessageflow::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_workmailmessageflow::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_workmailmessageflow::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workmailmessageflow`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/workmailmessageflow/src/config/endpoint.rs b/sdk/workmailmessageflow/src/config/endpoint.rs index 51a939e729bd..673b8d8531a1 100644 --- a/sdk/workmailmessageflow/src/config/endpoint.rs +++ b/sdk/workmailmessageflow/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -51,7 +50,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -198,7 +190,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -280,7 +268,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -301,7 +288,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -317,7 +303,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -338,7 +323,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -357,7 +341,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -378,7 +361,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -394,7 +376,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -415,7 +396,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -435,7 +415,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -454,7 +433,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -471,7 +449,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -491,7 +468,6 @@ mod test { /// Missing region #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -500,6 +476,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon WorkMail Message Flow +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -536,27 +576,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/workspaces/src/config.rs b/sdk/workspaces/src/config.rs index a21b889f41da..1ae91c5ea9f3 100644 --- a/sdk/workspaces/src/config.rs +++ b/sdk/workspaces/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workspaces`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_workspaces::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_workspaces::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_workspaces::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_workspaces::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_workspaces::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workspaces`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/workspaces/src/config/endpoint.rs b/sdk/workspaces/src/config/endpoint.rs index 61e2c3287a3f..4db6746f7323 100644 --- a/sdk/workspaces/src/config/endpoint.rs +++ b/sdk/workspaces/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -303,7 +290,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -324,7 +310,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -387,7 +370,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -408,7 +390,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -429,7 +410,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -471,7 +450,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -492,7 +470,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -534,7 +510,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -555,7 +530,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -576,7 +550,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -616,7 +588,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -637,7 +608,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -653,7 +623,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -674,7 +643,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -693,7 +661,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -714,7 +681,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -730,7 +696,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -750,7 +715,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -769,7 +733,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -786,7 +749,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -806,7 +768,6 @@ mod test { /// Missing region #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -815,6 +776,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon WorkSpaces +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -851,27 +876,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/workspacesweb/src/config.rs b/sdk/workspacesweb/src/config.rs index e27ee26ce060..f7c43e4edb4b 100644 --- a/sdk/workspacesweb/src/config.rs +++ b/sdk/workspacesweb/src/config.rs @@ -241,63 +241,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workspacesweb`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_workspacesweb::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_workspacesweb::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_workspacesweb::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_workspacesweb::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_workspacesweb::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_workspacesweb`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -967,11 +950,10 @@ impl ServiceRuntimePlugin { ::std::option::Option::Some(cfg.freeze()) }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1163,7 +1145,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/workspacesweb/src/config/endpoint.rs b/sdk/workspacesweb/src/config/endpoint.rs index fc7202056b04..d82d9ce4acda 100644 --- a/sdk/workspacesweb/src/config/endpoint.rs +++ b/sdk/workspacesweb/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -93,7 +90,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -114,7 +110,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -156,7 +150,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -177,7 +170,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -240,7 +230,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -261,7 +250,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -322,7 +308,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -343,7 +328,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -359,7 +343,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -380,7 +363,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -399,7 +381,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -420,7 +401,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -436,7 +416,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -457,7 +436,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -477,7 +455,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -496,7 +473,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -513,7 +489,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -533,7 +508,6 @@ mod test { /// Missing region #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -542,6 +516,70 @@ mod test { } } +/// Endpoint resolver trait specific to Amazon WorkSpaces Web +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -578,27 +616,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/sdk/xray/src/config.rs b/sdk/xray/src/config.rs index c9447047af05..29009fb11319 100644 --- a/sdk/xray/src/config.rs +++ b/sdk/xray/src/config.rs @@ -225,63 +225,46 @@ impl Builder { } /// Sets the endpoint resolver to use when making requests. /// - /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. - /// - /// /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_xray`. + + /// + /// Note: setting an endpoint resolver will replace any endpoint URL that has been set. + /// This method accepts an endpoint resolver [specific to this service](crate::config::endpoint::ResolveEndpoint). If you want to + /// provide a shared endpoint resolver, use [`Self::set_endpoint_resolver`]. /// /// # Examples + /// Create a custom endpoint resolver that resolves a different endpoing per-stage, e.g. staging vs. production. /// ```no_run - /// use aws_smithy_http::endpoint; - /// use aws_sdk_xray::config::endpoint::{Params as EndpointParams, DefaultResolver}; - /// /// Endpoint resolver which adds a prefix to the generated endpoint + /// use aws_sdk_xray::config::endpoint::{ResolveEndpoint, EndpointFuture, Params, Endpoint}; /// #[derive(Debug)] - /// struct PrefixResolver { - /// base_resolver: DefaultResolver, - /// prefix: String - /// } - /// impl endpoint::ResolveEndpoint for PrefixResolver { - /// fn resolve_endpoint(&self, params: &EndpointParams) -> endpoint::Result { - /// self.base_resolver - /// .resolve_endpoint(params) - /// .map(|ep|{ - /// let url = ep.url().to_string(); - /// ep.into_builder().url(format!("{}.{}", &self.prefix, url)).build() - /// }) - /// } + /// struct StageResolver { stage: String } + /// impl ResolveEndpoint for StageResolver { + /// fn resolve_endpoint(&self, params: &Params) -> EndpointFuture<'_> { + /// let stage = &self.stage; + /// EndpointFuture::ready(Ok(Endpoint::builder().url(format!("{stage}.myservice.com")).build())) + /// } /// } - /// let prefix_resolver = PrefixResolver { - /// base_resolver: DefaultResolver::new(), - /// prefix: "subdomain".to_string() - /// }; - /// let config = aws_sdk_xray::Config::builder().endpoint_resolver(prefix_resolver); + /// let resolver = StageResolver { stage: std::env::var("STAGE").unwrap() }; + /// let config = aws_sdk_xray::Config::builder().endpoint_resolver(resolver).build(); + /// let client = aws_sdk_xray::Client::from_conf(config); /// ``` - - pub fn endpoint_resolver( - mut self, - endpoint_resolver: impl ::aws_smithy_http::endpoint::ResolveEndpoint + 'static, - ) -> Self { - self.set_endpoint_resolver(::std::option::Option::Some(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - endpoint_resolver, - ))); + pub fn endpoint_resolver(mut self, endpoint_resolver: impl crate::config::endpoint::ResolveEndpoint + 'static) -> Self { + self.set_endpoint_resolver(::std::option::Option::Some(endpoint_resolver.into_shared_resolver())); self } /// Sets the endpoint resolver to use when making requests. /// + /// When unset, the client will used a generated endpoint resolver based on the endpoint resolution /// rules for `aws_sdk_xray`. pub fn set_endpoint_resolver( &mut self, - endpoint_resolver: ::std::option::Option<::aws_smithy_http::endpoint::SharedEndpointResolver>, + endpoint_resolver: ::std::option::Option<::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver>, ) -> &mut Self { - self.runtime_components.set_endpoint_resolver(endpoint_resolver.map(|r| { - ::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::::new( - ::aws_smithy_http::endpoint::SharedEndpointResolver::new(r), - ) - })); + self.runtime_components.set_endpoint_resolver(endpoint_resolver); self } /// Set the retry_config for the builder @@ -946,11 +929,10 @@ impl ServiceRuntimePlugin { pub fn new(_service_config: crate::config::Config) -> Self { let config = { None }; let mut runtime_components = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ServiceRuntimePlugin"); - runtime_components.set_endpoint_resolver(Some(::aws_smithy_runtime::client::orchestrator::endpoints::DefaultEndpointResolver::< - crate::config::endpoint::Params, - >::new(::aws_smithy_http::endpoint::SharedEndpointResolver::new( - crate::config::endpoint::DefaultResolver::new(), - )))); + runtime_components.set_endpoint_resolver(Some({ + use crate::config::endpoint::ResolveEndpoint; + crate::config::endpoint::DefaultResolver::new().into_shared_resolver() + })); runtime_components.push_interceptor(::aws_smithy_runtime::client::http::connection_poisoning::ConnectionPoisoningInterceptor::new()); runtime_components.push_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::HttpStatusCodeClassifier::default()); runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new()); @@ -1142,7 +1124,7 @@ pub(crate) fn base_client_runtime_plugins(mut config: crate::Config) -> ::aws_sm /// Types needed to configure endpoint resolution. pub mod endpoint; -/// Types needed to implement [`Interceptor`](crate::config::Interceptor). +/// Types needed to implement [`Intercept`](crate::config::Intercept). pub mod interceptors; /// Retry configuration. diff --git a/sdk/xray/src/config/endpoint.rs b/sdk/xray/src/config/endpoint.rs index 6ba73c41a0b5..2ed6d093acb4 100644 --- a/sdk/xray/src/config/endpoint.rs +++ b/sdk/xray/src/config/endpoint.rs @@ -1,6 +1,7 @@ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -pub use ::aws_smithy_http::endpoint::ResolveEndpoint; -pub use ::aws_smithy_http::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_runtime_api::client::endpoint::EndpointFuture; +pub use ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver; +pub use ::aws_smithy_types::endpoint::Endpoint; /// #[cfg(test)] @@ -9,7 +10,6 @@ mod test { /// For region af-south-1 with FIPS disabled and DualStack disabled #[test] fn test_1() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("af-south-1".to_string()) .use_fips(false) @@ -30,7 +30,6 @@ mod test { /// For region ap-east-1 with FIPS disabled and DualStack disabled #[test] fn test_2() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-east-1".to_string()) .use_fips(false) @@ -51,7 +50,6 @@ mod test { /// For region ap-northeast-1 with FIPS disabled and DualStack disabled #[test] fn test_3() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-1".to_string()) .use_fips(false) @@ -72,7 +70,6 @@ mod test { /// For region ap-northeast-2 with FIPS disabled and DualStack disabled #[test] fn test_4() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-2".to_string()) .use_fips(false) @@ -93,7 +90,6 @@ mod test { /// For region ap-northeast-3 with FIPS disabled and DualStack disabled #[test] fn test_5() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-northeast-3".to_string()) .use_fips(false) @@ -114,7 +110,6 @@ mod test { /// For region ap-south-1 with FIPS disabled and DualStack disabled #[test] fn test_6() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-south-1".to_string()) .use_fips(false) @@ -135,7 +130,6 @@ mod test { /// For region ap-southeast-1 with FIPS disabled and DualStack disabled #[test] fn test_7() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-1".to_string()) .use_fips(false) @@ -156,7 +150,6 @@ mod test { /// For region ap-southeast-2 with FIPS disabled and DualStack disabled #[test] fn test_8() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-2".to_string()) .use_fips(false) @@ -177,7 +170,6 @@ mod test { /// For region ap-southeast-3 with FIPS disabled and DualStack disabled #[test] fn test_9() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ap-southeast-3".to_string()) .use_fips(false) @@ -198,7 +190,6 @@ mod test { /// For region ca-central-1 with FIPS disabled and DualStack disabled #[test] fn test_10() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("ca-central-1".to_string()) .use_fips(false) @@ -219,7 +210,6 @@ mod test { /// For region eu-central-1 with FIPS disabled and DualStack disabled #[test] fn test_11() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-central-1".to_string()) .use_fips(false) @@ -240,7 +230,6 @@ mod test { /// For region eu-north-1 with FIPS disabled and DualStack disabled #[test] fn test_12() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-north-1".to_string()) .use_fips(false) @@ -261,7 +250,6 @@ mod test { /// For region eu-south-1 with FIPS disabled and DualStack disabled #[test] fn test_13() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-south-1".to_string()) .use_fips(false) @@ -282,7 +270,6 @@ mod test { /// For region eu-west-1 with FIPS disabled and DualStack disabled #[test] fn test_14() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-1".to_string()) .use_fips(false) @@ -303,7 +290,6 @@ mod test { /// For region eu-west-2 with FIPS disabled and DualStack disabled #[test] fn test_15() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-2".to_string()) .use_fips(false) @@ -324,7 +310,6 @@ mod test { /// For region eu-west-3 with FIPS disabled and DualStack disabled #[test] fn test_16() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("eu-west-3".to_string()) .use_fips(false) @@ -345,7 +330,6 @@ mod test { /// For region me-south-1 with FIPS disabled and DualStack disabled #[test] fn test_17() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("me-south-1".to_string()) .use_fips(false) @@ -366,7 +350,6 @@ mod test { /// For region sa-east-1 with FIPS disabled and DualStack disabled #[test] fn test_18() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("sa-east-1".to_string()) .use_fips(false) @@ -387,7 +370,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack disabled #[test] fn test_19() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -408,7 +390,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack disabled #[test] fn test_20() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -429,7 +410,6 @@ mod test { /// For region us-east-2 with FIPS disabled and DualStack disabled #[test] fn test_21() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(false) @@ -450,7 +430,6 @@ mod test { /// For region us-east-2 with FIPS enabled and DualStack disabled #[test] fn test_22() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-2".to_string()) .use_fips(true) @@ -471,7 +450,6 @@ mod test { /// For region us-west-1 with FIPS disabled and DualStack disabled #[test] fn test_23() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(false) @@ -492,7 +470,6 @@ mod test { /// For region us-west-1 with FIPS enabled and DualStack disabled #[test] fn test_24() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-1".to_string()) .use_fips(true) @@ -513,7 +490,6 @@ mod test { /// For region us-west-2 with FIPS disabled and DualStack disabled #[test] fn test_25() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(false) @@ -534,7 +510,6 @@ mod test { /// For region us-west-2 with FIPS enabled and DualStack disabled #[test] fn test_26() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-west-2".to_string()) .use_fips(true) @@ -555,7 +530,6 @@ mod test { /// For region us-east-1 with FIPS enabled and DualStack enabled #[test] fn test_27() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -576,7 +550,6 @@ mod test { /// For region us-east-1 with FIPS disabled and DualStack enabled #[test] fn test_28() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -597,7 +570,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack disabled #[test] fn test_29() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -618,7 +590,6 @@ mod test { /// For region cn-northwest-1 with FIPS disabled and DualStack disabled #[test] fn test_30() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-northwest-1".to_string()) .use_fips(false) @@ -639,7 +610,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack enabled #[test] fn test_31() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -660,7 +630,6 @@ mod test { /// For region cn-north-1 with FIPS enabled and DualStack disabled #[test] fn test_32() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(true) @@ -681,7 +650,6 @@ mod test { /// For region cn-north-1 with FIPS disabled and DualStack enabled #[test] fn test_33() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("cn-north-1".to_string()) .use_fips(false) @@ -702,7 +670,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack disabled #[test] fn test_34() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -723,7 +690,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack disabled #[test] fn test_35() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -744,7 +710,6 @@ mod test { /// For region us-gov-west-1 with FIPS disabled and DualStack disabled #[test] fn test_36() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(false) @@ -765,7 +730,6 @@ mod test { /// For region us-gov-west-1 with FIPS enabled and DualStack disabled #[test] fn test_37() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-west-1".to_string()) .use_fips(true) @@ -786,7 +750,6 @@ mod test { /// For region us-gov-east-1 with FIPS enabled and DualStack enabled #[test] fn test_38() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(true) @@ -807,7 +770,6 @@ mod test { /// For region us-gov-east-1 with FIPS disabled and DualStack enabled #[test] fn test_39() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-gov-east-1".to_string()) .use_fips(false) @@ -828,7 +790,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack enabled #[test] fn test_40() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -847,7 +808,6 @@ mod test { /// For region us-iso-east-1 with FIPS enabled and DualStack disabled #[test] fn test_41() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(true) @@ -868,7 +828,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack enabled #[test] fn test_42() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -884,7 +843,6 @@ mod test { /// For region us-iso-east-1 with FIPS disabled and DualStack disabled #[test] fn test_43() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-iso-east-1".to_string()) .use_fips(false) @@ -905,7 +863,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack enabled #[test] fn test_44() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -924,7 +881,6 @@ mod test { /// For region us-isob-east-1 with FIPS enabled and DualStack disabled #[test] fn test_45() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(true) @@ -945,7 +901,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack enabled #[test] fn test_46() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -961,7 +916,6 @@ mod test { /// For region us-isob-east-1 with FIPS disabled and DualStack disabled #[test] fn test_47() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-isob-east-1".to_string()) .use_fips(false) @@ -982,7 +936,6 @@ mod test { /// For custom endpoint with region set and fips disabled and dualstack disabled #[test] fn test_48() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1002,7 +955,6 @@ mod test { /// For custom endpoint with region not set and fips disabled and dualstack disabled #[test] fn test_49() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .use_fips(false) .use_dual_stack(false) @@ -1021,7 +973,6 @@ mod test { /// For custom endpoint with fips enabled and dualstack disabled #[test] fn test_50() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(true) @@ -1038,7 +989,6 @@ mod test { /// For custom endpoint with fips disabled and dualstack enabled #[test] fn test_51() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder() .region("us-east-1".to_string()) .use_fips(false) @@ -1058,7 +1008,6 @@ mod test { /// Missing region #[test] fn test_52() { - use ::aws_smithy_http::endpoint::ResolveEndpoint; let params = crate::config::endpoint::Params::builder().build().expect("invalid params"); let resolver = crate::config::endpoint::DefaultResolver::new(); let endpoint = resolver.resolve_endpoint(¶ms); @@ -1067,6 +1016,70 @@ mod test { } } +/// Endpoint resolver trait specific to AWS X-Ray +pub trait ResolveEndpoint: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug { + /// Resolve an endpoint with the given parameters + fn resolve_endpoint<'a>(&'a self, params: &'a crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a>; + + /// Convert this service-specific resolver into a `SharedEndpointResolver` + /// + /// The resulting resolver will downcast `EndpointResolverParams` into `crate::config::endpoint::Params`. + fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver + where + Self: Sized + 'static, + { + ::aws_smithy_runtime_api::client::endpoint::SharedEndpointResolver::new(DowncastParams(self)) + } +} + +#[derive(Debug)] +struct DowncastParams(T); +impl ::aws_smithy_runtime_api::client::endpoint::ResolveEndpoint for DowncastParams +where + T: ResolveEndpoint, +{ + fn resolve_endpoint<'a>( + &'a self, + params: &'a ::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams, + ) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture<'a> { + let ep = match params.get::() { + Some(params) => self.0.resolve_endpoint(params), + None => ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(Err("params of expected type was not present".into())), + }; + ep + } +} + +/// The default endpoint resolver +#[derive(Debug, Default)] +pub struct DefaultResolver { + partition_resolver: crate::endpoint_lib::partition::PartitionResolver, +} + +impl DefaultResolver { + /// Create a new endpoint resolver with default settings + pub fn new() -> Self { + Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } + } + + fn resolve_endpoint( + &self, + params: &crate::config::endpoint::Params, + ) -> Result<::aws_smithy_types::endpoint::Endpoint, ::aws_smithy_runtime_api::box_error::BoxError> { + let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); + Ok( + crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) + .map_err(|err| err.with_source(diagnostic_collector.take_last_error()))?, + ) + } +} + +impl crate::config::endpoint::ResolveEndpoint for DefaultResolver { + fn resolve_endpoint(&self, params: &crate::config::endpoint::Params) -> ::aws_smithy_runtime_api::client::endpoint::EndpointFuture { + ::aws_smithy_runtime_api::client::endpoint::EndpointFuture::ready(self.resolve_endpoint(params)) + } +} + #[non_exhaustive] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)] /// Configuration parameters for resolving the correct endpoint @@ -1103,27 +1116,6 @@ impl Params { } } -/// The default endpoint resolver -#[derive(Debug, Default)] -pub struct DefaultResolver { - partition_resolver: crate::endpoint_lib::partition::PartitionResolver, -} - -impl DefaultResolver { - /// Create a new endpoint resolver with default settings - pub fn new() -> Self { - Self { partition_resolver: crate::endpoint_lib::partition::PartitionResolver::new_from_json(b"{\"version\":\"1.1\",\"partitions\":[{\"id\":\"aws\",\"regionRegex\":\"^(us|eu|ap|sa|ca|me|af)-\\\\w+-\\\\d+$\",\"regions\":{\"af-south-1\":{},\"ap-east-1\":{},\"ap-northeast-1\":{},\"ap-northeast-2\":{},\"ap-northeast-3\":{},\"ap-south-1\":{},\"ap-southeast-1\":{},\"ap-southeast-2\":{},\"ap-southeast-3\":{},\"ca-central-1\":{},\"eu-central-1\":{},\"eu-north-1\":{},\"eu-south-1\":{},\"eu-west-1\":{},\"eu-west-2\":{},\"eu-west-3\":{},\"me-central-1\":{},\"me-south-1\":{},\"sa-east-1\":{},\"us-east-1\":{},\"us-east-2\":{},\"us-west-1\":{},\"us-west-2\":{},\"aws-global\":{}},\"outputs\":{\"name\":\"aws\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-us-gov\",\"regionRegex\":\"^us\\\\-gov\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"us-gov-west-1\":{},\"us-gov-east-1\":{},\"aws-us-gov-global\":{}},\"outputs\":{\"name\":\"aws-us-gov\",\"dnsSuffix\":\"amazonaws.com\",\"dualStackDnsSuffix\":\"api.aws\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-cn\",\"regionRegex\":\"^cn\\\\-\\\\w+\\\\-\\\\d+$\",\"regions\":{\"cn-north-1\":{},\"cn-northwest-1\":{},\"aws-cn-global\":{}},\"outputs\":{\"name\":\"aws-cn\",\"dnsSuffix\":\"amazonaws.com.cn\",\"dualStackDnsSuffix\":\"api.amazonwebservices.com.cn\",\"supportsFIPS\":true,\"supportsDualStack\":true}},{\"id\":\"aws-iso\",\"regionRegex\":\"^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso\",\"dnsSuffix\":\"c2s.ic.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"c2s.ic.gov\"},\"regions\":{\"us-iso-east-1\":{},\"us-iso-west-1\":{},\"aws-iso-global\":{}}},{\"id\":\"aws-iso-b\",\"regionRegex\":\"^us\\\\-isob\\\\-\\\\w+\\\\-\\\\d+$\",\"outputs\":{\"name\":\"aws-iso-b\",\"dnsSuffix\":\"sc2s.sgov.gov\",\"supportsFIPS\":true,\"supportsDualStack\":false,\"dualStackDnsSuffix\":\"sc2s.sgov.gov\"},\"regions\":{\"us-isob-east-1\":{},\"aws-iso-b-global\":{}}}]}").expect("valid JSON") } - } -} - -impl ::aws_smithy_http::endpoint::ResolveEndpoint for DefaultResolver { - fn resolve_endpoint(&self, params: &Params) -> ::aws_smithy_http::endpoint::Result { - let mut diagnostic_collector = crate::endpoint_lib::diagnostic::DiagnosticCollector::new(); - crate::config::endpoint::internals::resolve_endpoint(params, &mut diagnostic_collector, &self.partition_resolver) - .map_err(|err| err.with_source(diagnostic_collector.take_last_error())) - } -} - /// Builder for [`Params`] #[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)] pub struct ParamsBuilder { diff --git a/versions.toml b/versions.toml index ef8ce2a63d5c..51f1d864981d 100644 --- a/versions.toml +++ b/versions.toml @@ -1,4 +1,4 @@ -smithy_rs_revision = 'bcfc211277c9593037fc63ce42f52c50135eb4ef' +smithy_rs_revision = '12fa4d3963eaee9105339971ff1e6e1e185c95fd' aws_doc_sdk_examples_revision = 'dc64af92d9c1780e628ab8b9f665e0490dfad6c8' [manual_interventions] @@ -41,2137 +41,2137 @@ source_hash = '749e014876859d0e967de5fc4ea67637c77f2267153239e1fd5c1a43331a69f0' [crates.aws-sdk-accessanalyzer] category = 'AwsSdk' version = '0.35.0' -source_hash = 'cd2f13ad1dbe8185ee3bb8ca1347aa990c31983c45028ab70a2c75ff9ccda66b' +source_hash = 'b700ccb55ac9e999376aa91f16f0da95a2640b63f55c1d74f6149fa7725bf6b4' model_hash = '683b125a02a32bf12faf4dd3fdcbc948d8c81ac45d17a646bdbeb5460c8d943f' [crates.aws-sdk-account] category = 'AwsSdk' version = '0.35.0' -source_hash = 'be6ebe1606f8bbfcaf9fa42134546aea0b71f89df45b6289b6bf0016ab6c3db8' +source_hash = '83707358279824d24d6c39be77f3984032241d99257642c9d0059821117cb78a' model_hash = '00cf828a77b72627775d41967bbf70303075c0daca8ff2321f98649d6df6d0a4' [crates.aws-sdk-acm] category = 'AwsSdk' version = '0.35.0' -source_hash = '254e83b83c2d728d24ec06750627b5f13e7d17ce833f968bbf5c1bc6d4d2bd56' +source_hash = '7032efdaeabbe5b8f8c0da4cd9f39d5bca364b9615275c5d1dc16596db7cbbe3' model_hash = '8f48debe88301a0cf3061729bf596074d301ce724a27b5b38b2b56da5ae231ce' [crates.aws-sdk-acmpca] category = 'AwsSdk' version = '0.35.0' -source_hash = '8746499e2b64caad46637d9b10d377ad470d49615af17a811c57ec8a9b447672' +source_hash = '1cbac56d5cdd001bc71e8951f4b13254a4406d130c889b707ee8378435d3bdb0' model_hash = 'e58062fc9dcc835060e9a1501dfca2ce3ff626013c69bcdccd94d0cbc9603087' [crates.aws-sdk-alexaforbusiness] category = 'AwsSdk' version = '0.35.0' -source_hash = '5b9bac7279c22fcb5e1c1c3496a611898cbb40f02a8fb904208258bb801dbbc4' +source_hash = '6146bb41dd6a838b8cb38dd5fab7bc8edf3d03c5a775c298e26ff9ad2d3d30b0' model_hash = 'e641e6c69722adc63666041d7efc36cf0dc9decce7fb1caf46de39b7860b7197' [crates.aws-sdk-amp] category = 'AwsSdk' version = '0.35.0' -source_hash = 'fccbc42d16751aa555e3e07bda824f19ca9e026285903633e6e30d74d94e97bc' +source_hash = '670e7e8245015f6328fe35255e37fbf2c9603de6b929c814755a11525b8840f8' model_hash = '14020a8c9bd25882b16ef2d7d2081541f698b5051c702c319d13b3c3cd4e6644' [crates.aws-sdk-amplify] category = 'AwsSdk' version = '0.35.0' -source_hash = '2458d2f8f5af432c4caae8a26606d743f5406404cc4dad6e3fd851edb7382810' +source_hash = '744904962dc93feb084781eeddb17e2264e582bea0094cbef1f357d8a454cd73' model_hash = 'f78612b62fc7f991e77fa62f21d690041cd5b7a3e5a1bd4a4195b7f33d9a475f' [crates.aws-sdk-amplifybackend] category = 'AwsSdk' version = '0.35.0' -source_hash = '8158277ce4029c01eff81471c3f3ee319cf2f592c39dd207bffefbaafde187fb' +source_hash = '3ec8998214b38b6cadcf0bd757a284fc914f023078cae83d7865dff804193abc' model_hash = '55ebcb28813fcd6e41309a5113a3ea35ffec5306a194a215a22bc796cd6d4729' [crates.aws-sdk-amplifyuibuilder] category = 'AwsSdk' version = '0.35.0' -source_hash = 'bf5a8228af5dfcf2e9b50a7ec86f0dc4d447843cd6de2822b4a5fc7cfa3a811e' +source_hash = 'b54002e56b3f28cb61fd92a7cc5f2ca3319ee408de918ac9a572f39bec736971' model_hash = '8135f704673dbcc6d8493c8e80ee1934ddabaf7ceff9a96fb37bd9c6230901f9' [crates.aws-sdk-apigateway] category = 'AwsSdk' version = '0.35.0' -source_hash = 'acdbdb7d6fd570c35968e37c0889b0e69e71bf7d8e06736f5f577543406245d5' +source_hash = '4ad3a53c7ebe3fc38030c16eeb4d161f1da365a8182888645bbb6adf88e066dd' model_hash = '921f9c7a6ab96ea8baef934e51e6865c6ad092c5c3b1bb0969dde2427bc1d77c' [crates.aws-sdk-apigatewaymanagement] category = 'AwsSdk' version = '0.35.0' -source_hash = '8f09eeb11b583501756f0147cf812564214db614acc85fb8a5c135479b9404db' +source_hash = 'e7b1b4788e70edd2b0973554bbd57d072d5fab99e46da2806c818356fc4a2042' model_hash = 'da3fc1b71d982864cd77e0187eb3078f4443e8d9da188cbb5db04cef126e46b6' [crates.aws-sdk-apigatewayv2] category = 'AwsSdk' version = '0.35.0' -source_hash = '33b7931134772541e524745d5ccb28e7a6465988c90109aeab266ab7aac7d0d2' +source_hash = '5ec7aef8327ee3b01762fc1420470f1d9022aa448d997a001e40bcd1f3c20467' model_hash = 'd78aa2f44c0462bc70277b72ba410145023564b98a69babce0b6aa1afa1dedd2' [crates.aws-sdk-appconfig] category = 'AwsSdk' version = '0.35.0' -source_hash = '5cb9dab5fa8e7fc4ab6b87e4e5c8befabbc7385efecee35e404183bd720558e5' +source_hash = '8b7c27d347b8ba90dcf7f4ba14992814738b059d7187e83d582c538be817df7a' model_hash = '5cf3d095c7d08a93dfaa8a39e821028e64cb37bdf0a6ef314e81920748da1ce5' [crates.aws-sdk-appconfigdata] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd3021c4057e17d895e739dcfbfa8e8c9b0f5c17879e0f05276b38bc4ef37893d' +source_hash = '27b2d7991645348940d908737210181937dd394b60a0da6e5604925582a79738' model_hash = '60cc68e5a760a41ce02268e551d29f8ab30e9bef5f1330cc2d006183010156d2' [crates.aws-sdk-appfabric] category = 'AwsSdk' version = '0.7.0' -source_hash = '22649de7d83019e8803ffaacd7ec3ec2d082459bf69e7fae8353fcfe8deb9d5e' +source_hash = '30a36b6523d355050a9032ecd27bb61a923f100fef9f271cdb4fd4e0f2f6ba17' model_hash = '2045e5882967d5ddc7289898cab3875087d7e26abd9522fbabf3f6642e17cd8d' [crates.aws-sdk-appflow] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c9c30008842577d7ef445fa372f0856bb412396a8e39086a4b55219443a526da' +source_hash = '32537ad3f31ccde3e4d35679549f620e326ac19fb3bcef1494a21e9624835a0b' model_hash = '2e052cb3e79396e21e941fefb2445742cf5a666a1b9e0890414357db37678017' [crates.aws-sdk-appintegrations] category = 'AwsSdk' version = '0.35.0' -source_hash = '21ec5c1a837c3083d431f0ec5e2173d0fc8165ef8c3755099ebd85d50c49373b' +source_hash = '3932660dd0af3c1935e115b50d8dcd99acbf2ffb2e51d193faf98e539383ca7c' model_hash = 'ace0ca1699ea905ffb1ee0a089c972632e0cbb2650d56d4b2ab4bd2649158af8' [crates.aws-sdk-applicationautoscaling] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c346349677b2b90d777b15b888cc6dd7ba99c6fb778a537f3f58a02265142eab' +source_hash = 'f5721a66c11a59c96b2d433c243f22225ceb82501ac008ad994e4c81a97de8d9' model_hash = '608da862b5dac5c94e97cedf83baefeaf2ca5d41a8bf1a4b23c6dfdcf6649b96' [crates.aws-sdk-applicationcostprofiler] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e8178da95fb57ee8720e928fe6e3cf45b847451d62afd1594d6b3451ae6b4c02' +source_hash = '8d8038981d7dcd4c494826421bf3ff6cb7e9a04512f698ee5f297682b93fc353' model_hash = '87f8b863a2d1b4902b1e5c1f822a2c3c31821a2885534c3080b7cdd70383fb6a' [crates.aws-sdk-applicationdiscovery] category = 'AwsSdk' version = '0.35.0' -source_hash = 'afa7e88dffadc5fcd454880d5d34320d02aa50286ce2373d56d534b709d4a99f' +source_hash = 'b24113eb504a167e3277e2c0fdf46bc2fe2ca4f8b0310ddef9a7d44232eb44de' model_hash = '4aaa6f2a81b29b10a4fdefa4f5b40aa73581330a36badb5b0e11b5193c1a5a68' [crates.aws-sdk-applicationinsights] category = 'AwsSdk' version = '0.35.0' -source_hash = 'b15544f5cd1b3aedfd3a781d5aa4097570a3ad1389d1e5e6cf0a726502f30106' +source_hash = 'b7124c582ac5b96d2a9fff5409305d3bdf79ab9b3c39418bc03f64a893975488' model_hash = 'abe435ba1db05a30fe96e06727517bbe7f9c3d25823955fb0e290035df1af69f' [crates.aws-sdk-appmesh] category = 'AwsSdk' version = '0.35.0' -source_hash = '9c9a8e8d8aee018ac182edd6bb3fddf77e5886c3e46c939eb2fc7d5f18e1a595' +source_hash = '52f8b0e07d80bdb2f7d45f266ab7440d83aec5e51d6fcb9feb96e8d1e2be391f' model_hash = '7c91464c3fe7ed4dcbfce0bc1d5bb2f38d5ea5a2fd1c211e3d92704993ca92cf' [crates.aws-sdk-apprunner] category = 'AwsSdk' version = '0.35.0' -source_hash = '2b679c9e3f46933f2a5bea14fb5c93ff7d7e52ac34321b420181b08483926192' +source_hash = 'f7f9283f4ed5936bda9588503531d08a5a00875b7f001d77fb9cf0b3165c4ce5' model_hash = 'fee74e713a972f6477e24fc40ea4448f54308abf4be17586d1bfa4ba190572e6' [crates.aws-sdk-appstream] category = 'AwsSdk' version = '0.35.0' -source_hash = '606a7a9b7f3430e6e6588be1284c6ffda2c6d0f4191e2c11ff96f0c707e909e7' +source_hash = 'b31f19beb75acd2756f32b2de4305fbd96df902d48463eec7ed86e9d294fdd99' model_hash = 'b228d8d874a62056bc87b192feb89a159318d6684c6b5da021ff54f07a89a4b4' [crates.aws-sdk-appsync] category = 'AwsSdk' version = '0.35.0' -source_hash = '613f87221b8e55f497aca621acfc8e86b819e5680d1c7e742053b2e7d31f02f3' +source_hash = '7a4e99a30d774a65481666b99b3273f68e0fbaa3d340783c01e5da0a63a840e3' model_hash = '0a2c702a8974a46739f3387f196de7faaa72701f1611b47616036e286492c482' [crates.aws-sdk-arczonalshift] category = 'AwsSdk' version = '0.13.0' -source_hash = '5828e5e76895164dd90e29cb3d73135c536a298b68b1193afe9f66dccd311158' +source_hash = '889dd63706a2794327280c6fa3d1df97fe92745dfe37d2ea911723d3863c544e' model_hash = '822429af8874f4bf10181a0c0dc17d56841d24fcf5293418df761249f31f23b3' [crates.aws-sdk-athena] category = 'AwsSdk' version = '0.35.0' -source_hash = '1bdc8fcc17311978ce1b0df0203fb60bafa8fcd55d6ae5349c37fcdbab395fb3' +source_hash = '54fa96f0b4361f05b0ad4192a8fd6d61979f2510ff5a1a447f96ce144fc2e96e' model_hash = '685f498c4c7ba235ad3ace1d84a80a99e5e9bf2b8f5f37e586e7fcf87d1c08e7' [crates.aws-sdk-auditmanager] category = 'AwsSdk' version = '0.35.0' -source_hash = '85d97b90a85e08054e9271c0b86cf082811ac0c8b26b63742319b5a57b3c76d3' +source_hash = '41ded54b9371841f1f5f962b147a9d93dfa5aed10c88282727d96e48ed3dc428' model_hash = 'c07729a82666e5bfe3145b0c373b9942681081e39354f69083a1755adc502f76' [crates.aws-sdk-autoscaling] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e1cff131afeda1d6ff014afbef0b0016a9a7e7e98e496008148db686e7d8998b' +source_hash = 'e755164fe2f92bf127bc15821d7dadf564f0d786a24da8543aeb8691dafc5405' model_hash = 'a27a99a2469c3b8134a45b634740a5ae20b6b9a5e05ea790153d0c79a7133233' [crates.aws-sdk-autoscalingplans] category = 'AwsSdk' version = '0.35.0' -source_hash = '08c870b971971921b4d785bc97d8091b1527678213216b40cd3207e15d85b6d6' +source_hash = '3c38d1d2b6d1d863dc2b5e373d1177a7d4cbce4091e4e03f90cb3740d3b2b1ff' model_hash = '228b888792ce40aa06e158c9b654f5d46820d2d2a947936808ff6412c1b61b0f' [crates.aws-sdk-backup] category = 'AwsSdk' version = '0.35.0' -source_hash = '8b823f8355f7c041476ae1dab61318aa4a3268512e5f835f666a04e717776f6e' +source_hash = '2c66f4dd2b4f1e6cb1f6d6f9d26ef68995765ea609989744956fc18ac9d91cad' model_hash = '434160e83bbc461b7093637be5e3629f2445cc32de01dc47c3dc302261c16c9a' [crates.aws-sdk-backupgateway] category = 'AwsSdk' version = '0.35.0' -source_hash = '9275f1185431c56a946a4259d07ce8ab58acfba9f4b6180e2664a78b10cacbce' +source_hash = '1a686c832d396c9594ad5565cc503434ed9779dfbba0cc0a5a1a45b63e09c95f' model_hash = 'f14d6bf655e9a701fb322eef4a961b41aefb3c2686c5f9c48d8203bcda8df0e2' [crates.aws-sdk-backupstorage] category = 'AwsSdk' version = '0.18.0' -source_hash = 'e1bf1410d163fb02a345981493309a9bf2709764ef10e35f37f6b6f241211ced' +source_hash = 'e9c8b24589c51dc99bdb0a7020e733932e7cf235a042ed85a18950196c8e32ca' model_hash = '5deeed67469310f49246f94be4da914563959d5d88e75198e61deb441274d7df' [crates.aws-sdk-batch] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ec490fc8566d0b1b3aadd03450f87f0ae8f6c87a888f6d0f55650406de9b77b7' +source_hash = '7357d6dff1b4ed7c292f740a76a1599163e91c5792538063c82b7f3e7bfb0540' model_hash = '3765aa4ba983e46c1dfcc19283fdfdbd61a15b214531dd0a8607a85a2c2eb5ac' [crates.aws-sdk-bedrock] category = 'AwsSdk' version = '0.4.0' -source_hash = 'db04b8acaf9b6ae665f8835c0268607c2c3f66c476379691cdd7976b1876f4e9' +source_hash = '92bf43004fd6dc69b5b4f846b0b3544cef23058e67ea7c43d7def42e75832832' model_hash = '4616b442f54868478577197658ba1a61e532b9843bf09f1980382787892a0430' [crates.aws-sdk-bedrockruntime] category = 'AwsSdk' version = '0.4.0' -source_hash = 'f9b83ad5afde56a9cedbcbc200deef1a2bf11422e24abf36c93d07435e3533f2' +source_hash = '1b7cd9fa3299abad500279722662f01e2a53f7fbfd5cb8b3fe88cb56286bf8ae' model_hash = '1790bff3f22aef153fbe1d907eac2e55b79c6a1a818319b76e7b0fa21d76d869' [crates.aws-sdk-billingconductor] category = 'AwsSdk' version = '0.35.0' -source_hash = '793f01b08e1cc4680a13f27d97b150694b00df7873f3a1c8470a3a03d5362ebe' +source_hash = '69fed1d3cfb370a5e171af9093d175779551a3bc2112d38a0e52a2f95b2616b4' model_hash = 'd2388005b8cfab17dc1c921ba92b7c07b6078ac9e452d9dbc70b9b4f71b22aca' [crates.aws-sdk-braket] category = 'AwsSdk' version = '0.35.0' -source_hash = '22903fb526e7b85a07418f5a096dd296e847ce406c03ee4ccc64a5836f5d4549' +source_hash = '30792dd4899b3b0500444e5f63983f3d8c57641d4b94606b0f25ae54a920995c' model_hash = '9bd9abd04c8e7fe72804e10402db7098467d775634376b4059cb9c16d29074e8' [crates.aws-sdk-budgets] category = 'AwsSdk' version = '0.35.0' -source_hash = '48495338427aadc038436633c85e45330ccdf390e1e5e9a39ef7cbd2f5e0199a' +source_hash = '50ad4adf369055db67d265c7211367872f76c7fd965bd4d0024e1ce22a719ce2' model_hash = '03312a8563ba6d615995f0490f1d169fee1f5a508c6844da34372a3dcbea8c07' [crates.aws-sdk-chime] category = 'AwsSdk' version = '0.35.0' -source_hash = '4d31fa4f879587cb84d9b39b453267b583cc45198b353cee611527f9f28ed5cb' +source_hash = '8431f9d56e9f531ea39056b6b0b2f2fb0ad9bb5babeded0531ecd02f7ef608dc' model_hash = '26c01cbaa804d2bfd474705d4726a7ea82693d0ed5ca5117d11958e9a7feac3c' [crates.aws-sdk-chimesdkidentity] category = 'AwsSdk' version = '0.35.0' -source_hash = '4f79b0a3aee785a17cd3e2f09117c9297cee57c5a68f2d37b0db59677eae118d' +source_hash = '8d674744675492f843049ed5a69f568209649e9fdb10b83a402ba4a7c996a851' model_hash = 'bc1618d82f6503a626c4e9f1ddd5a1f2accda511152b4529964a8ea400ca9b2b' [crates.aws-sdk-chimesdkmediapipelines] category = 'AwsSdk' version = '0.35.0' -source_hash = '38ce342021c9db5500f47c40ffd481d3fe71c94833a0a2fd02d206390c2e60aa' +source_hash = 'ebb7e883931429a5c00540c7f0dfc20ed67c63de63402c28bff5e2d82f0445b8' model_hash = 'e340066bc58817310be45eb74044bc96f69e5d0903ee4e780bc7103649ab0ef8' [crates.aws-sdk-chimesdkmeetings] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c3e81fe4c3d2c1bda7730ca3bfc189204203085320a135dc9d42ee4bedbfec56' +source_hash = '4a6c3e925fbdf235b57c5968c539580c4d2fec89d1e78995196b02b768976af5' model_hash = '0a065459982c16a52fa04ae967097582b69a2bc8b0a17f7ec56a731d6fc443dc' [crates.aws-sdk-chimesdkmessaging] category = 'AwsSdk' version = '0.35.0' -source_hash = '35f02d95faca2179497b6eb5533c8df3a4af202d0429fbc14f1645bbb23fb742' +source_hash = '328ec31d2b7deed7091b78e92a02d5b34bb4c13048b99e9da3d18b724b21b374' model_hash = '7df60525433ab8706f92d474d4dad4c5dc972c6c853175a5678045482ef7a25f' [crates.aws-sdk-chimesdkvoice] category = 'AwsSdk' version = '0.13.0' -source_hash = '6c85d685f3d96ea7952b17f788dada74443f67d2f489d997368c0ca5aa3150e9' +source_hash = 'bc56ffe585d54dc9e12b24e5546fce3f13abd93970df90d199c9052d5d3d3c96' model_hash = '9745917dd01a57acd3677be5f9b8b4bd87e991d988dc28e6cc018ad35d85ecd2' [crates.aws-sdk-cleanrooms] category = 'AwsSdk' version = '0.12.0' -source_hash = '1793ef9564df09ad512f7231691517203feede464a51e004777e571af68e1acd' +source_hash = '7ccb6682d5af4131ab371bed707deaf9bf7aa229da165be39817c15be6353276' model_hash = 'df9dcb557f39262949471ac8398ff4efc360710b32a7f54681d445e6657d4f0d' [crates.aws-sdk-cloud9] category = 'AwsSdk' version = '0.35.0' -source_hash = '774516a889aaf7af12fbcd3c14be197f2cdf757a2fed7683b54f062885e585f4' +source_hash = 'bee2ab25c702e4c4eae7aa454f281d412c825adb95ba16c2cf24ca2d3c29b22e' model_hash = '7f9c8c45b24595a227a2532a444ba0ee3581f81962b44ad012604a2c50dc9cd8' [crates.aws-sdk-cloudcontrol] category = 'AwsSdk' version = '0.35.0' -source_hash = '21d96a4ebabf771f7ee93eed8021227b5f932209e2b7e03e2304b6be788b7653' +source_hash = '7f74c7f279d0043e72efcf113294d6be3a609e3bc9eb2664d67e3d734ef31847' model_hash = 'ec1e6b9e5b04e006be8d7222cb3269fd17ee775440fe919c6f89f77cb48b6f5d' [crates.aws-sdk-clouddirectory] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f4f35503913946fde4c6b1070f0dbfe2ee11ef619f31ef6d743db4aa5604d0a3' +source_hash = '217d7ae7827bfa774281e67a2545c743e8a28d5c62eb0fad11ad9e00896f45b4' model_hash = '3efd089f35a2a1b2bb697823c0e3438b63bb82f419d7aa21c622d872d14eef8f' [crates.aws-sdk-cloudformation] category = 'AwsSdk' version = '0.35.0' -source_hash = '8877cf95ec2c9f22a81f5057d1d9279aadceff441df379a296edc2b4b82445f8' +source_hash = '5409f65c9e642d37e3e0b0ebbd46b1e4e4e593654a8371484d8e034e74878274' model_hash = 'e7423ce150848dfd2583ca2cc65dea830427cd071f3ce9ae07c19e8595bd7675' [crates.aws-sdk-cloudfront] category = 'AwsSdk' version = '0.35.0' -source_hash = '0e91dc32e63138157dd54169728e590ae58f81727485df5600bc410f6f503c43' +source_hash = '103fb93cbe06547057180e15c5d882b6becc5392423087d4ebe2bc34774467b5' model_hash = '82c29e9bc3fab55f62b373c4cf4daa8ce27cabe8f4840c0648aa7ca51676f42b' [crates.aws-sdk-cloudhsm] category = 'AwsSdk' version = '0.35.0' -source_hash = 'db9ae091bc19a965611ecee39907468a736fbf653fdad0333cf7e7e1297b7194' +source_hash = 'df2a95e9c97347fdc62744a1aaee60050134a05129c09d1479063476858553de' model_hash = 'b65bf64ffb06d0d3e137a01014909833b0b4bc6ea9be28676d96e189387419ad' [crates.aws-sdk-cloudhsmv2] category = 'AwsSdk' version = '0.35.0' -source_hash = 'bb2dc0c51dce80a3b96c5dca115c62914088092315470de089bcb2d7b6514373' +source_hash = 'be5a408272fee771adf289000deb187c116a2578975b577caec9d1cf32c1cb2c' model_hash = 'cedd8afea0aba0fb8b8b87fc7410c0f7515805ea2cad8920905ab9ce7c41f6d3' [crates.aws-sdk-cloudsearch] category = 'AwsSdk' version = '0.35.0' -source_hash = '2571f58c1915db4da47c78c83b07626483649b9798917f1a55fbedfd4d3226d4' +source_hash = 'be2f3669f92b2471dcadf8ee2e374e2c582396ee7e4bd69e8eeb072bcdca42e0' model_hash = '1e81ce3fe0a460ec2087b1501bc19b837e1c829db6f155434cf7c677762b6b1a' [crates.aws-sdk-cloudsearchdomain] category = 'AwsSdk' version = '0.35.0' -source_hash = '4ec6fd3ff04a83a48d2fda9ad5e28d6dbae767e836afffb339e74cfd8886afd3' +source_hash = 'd33e0b68f011a718c8bacb91105928cb9751b2426563d07fed6e167c760f4036' model_hash = 'd47b34a47470d77273ac364c1ce141ff9ff69dde0b023433fd97645c7e5f4fbc' [crates.aws-sdk-cloudtrail] category = 'AwsSdk' version = '0.35.0' -source_hash = '0791ad9da1386f305d6564bc86f0aefda49fb504fceaa922a0e42fd1e1181357' +source_hash = '20b2d2246915c72d46f509cc1a3f8f3dd1ae53e1ae7da5d97de789085d037885' model_hash = '1d024e044f60977f413403bf4d8bc0dbd7dc6f88361b17eed557457aa1f02682' [crates.aws-sdk-cloudtraildata] category = 'AwsSdk' version = '0.11.0' -source_hash = '9b029f835d868d3b89969d55c42fd6087e76d0b345d79f8fe37742f7c24d074c' +source_hash = 'cfdb139d4b59bbb4d8eddd07b64d552a957da531c283cd31909b9d73fae24bd7' model_hash = 'b0fca8401448081d86469d214adf368b56a8a534032015ff2c80fe0bd86f2c7a' [crates.aws-sdk-cloudwatch] category = 'AwsSdk' version = '0.35.0' -source_hash = '1901efcf434ed0d8907109b313189e160e22f6efe914cda5d624f64769761608' +source_hash = '77e6fa4e04e9b7e2987b9047a3fe6e4762d1459350fe2565068c32be6202d87a' model_hash = '22156ea133f07c657b9ad6470e683736e66fe9d311274088043ca490cf65abc6' [crates.aws-sdk-cloudwatchevents] category = 'AwsSdk' version = '0.35.0' -source_hash = 'eb8fb793bf5a8de2c90ba3230ff96c6d0b1d91ba33b3f5b7d177542187688efb' +source_hash = '27e94bf3b331cfb41fee79ca4ba74e41e967f1f413dd83596b5d2cdc18dc207b' model_hash = '5497d1b84409af6543689f08c00475dd0942c86b4e575186d7c587da07ec97a0' [crates.aws-sdk-cloudwatchlogs] category = 'AwsSdk' version = '0.35.0' -source_hash = '4053f8c50fad7948982d5e178bed2a4d503ad6e85c1a31e5ab76e21a61df9403' +source_hash = '1af73bfd696100a9df0cc37b52f38cc19bbd940135a3a3e930551616bc7df4c7' model_hash = 'a753ccaefe2fa51c7e56e47177f9e4dce9403e7b106e907b39672c77b560bf2f' [crates.aws-sdk-codeartifact] category = 'AwsSdk' version = '0.35.0' -source_hash = '221dfc664f297f1d25291b487b44cc33681e1e7737f5b177dc5811c2b1fb331d' +source_hash = '50cb44df7fb2938d12776ced2c34f063f630903c6bed8a48ca3e529be04e10ed' model_hash = 'e2e9823e7ed4cdef9ed93b1ee9f740bc9b4d6778f053e8daa8cffa084d86e018' [crates.aws-sdk-codebuild] category = 'AwsSdk' version = '0.35.0' -source_hash = '27a82c7862ee9339c63b163e780f52929a5bec0fa789c2e9edde46bd3b919426' +source_hash = 'abc3be8f74b7c5e88b479554429f985d7e24c7b665ec13519e7f010020a4b144' model_hash = '4ed518f904ab7b2fbc60b8f483cb6d0348d4c138167706e942ab9e02ee5556dc' [crates.aws-sdk-codecatalyst] category = 'AwsSdk' version = '0.13.0' -source_hash = '1a337a4de53bbfe47dbe9048fdc358f95554272f401d2bf078f05248b510b8c4' +source_hash = '26a49d52cfd51aad5a7b0be262ee71ee05d30da6cff339863e4a63027409395a' model_hash = '70ce861f9b811a9c51c4693b95ce601a015157412267799cded85c25bdd6afb4' [crates.aws-sdk-codecommit] category = 'AwsSdk' version = '0.35.0' -source_hash = '3b4a60026b31ba6351c1d901201b4a00903d8e43137ebf3189fd16c12790285a' +source_hash = 'e15dbd38465e4ec5ab758f88fdce4479f4356ab7c1bf643290ca724ba7815c5b' model_hash = '1cb6d00c467528a6bf71c49c60d52bca105c4a37a5d3a59b0d2e6e069b211553' [crates.aws-sdk-codedeploy] category = 'AwsSdk' version = '0.35.0' -source_hash = '344008d46ceec7dd05fc024ba2f996142aa19ad7d2c7b788ed4d1fe3919c0857' +source_hash = 'b5169662f3b612efaa038898c33916c2115e8b26f152a3cb88d6dda08171d4d5' model_hash = '76b33b52ffbe8020e998aee4267044cd67aaa9e447fa214fa5c9a475d3374d7d' [crates.aws-sdk-codeguruprofiler] category = 'AwsSdk' version = '0.35.0' -source_hash = 'de52d3133f5347c19e43cc378f46477c9db376c43f57a4660c6d25d749bcae68' +source_hash = 'd6b140fee1cb606bb0aa6acd9606335108ebc00a857e53d92048cb8d5418b0d3' model_hash = 'f84648080798b37a359c18027550ebe7cf8dd9451542c6681724fef9799f8efa' [crates.aws-sdk-codegurureviewer] category = 'AwsSdk' version = '0.35.0' -source_hash = 'fde325ab0b3dcaca90b08ba5e0937d036eda17fcb36da1cb286dda871c6dd3ea' +source_hash = '2b0582a8a5d4742c86116ce61b9d84538e968b49599e99e36cb2a3b1711a7905' model_hash = 'fac22fabaf522bd84c34df1072d443821576dc651eade9cc63a740cc396fe7f2' [crates.aws-sdk-codegurusecurity] category = 'AwsSdk' version = '0.7.0' -source_hash = 'a029b6aa373b8742d9d437655743170dbe6b1a56e79ac9a0c9be7be97abe1bf7' +source_hash = '17a9778075f2a4f7bb561655c8a21e06bac1b645800ee8a26080a2c0d726f964' model_hash = 'e6dbdd5c1edc8e5ee9a04aa581531801648abebcaf4e0f221dfbb3d942c25764' [crates.aws-sdk-codepipeline] category = 'AwsSdk' version = '0.35.0' -source_hash = '4a7158eaeb4e9255f71ef43e884ee517b7c1d71dbdcba1345cc21382ec497876' +source_hash = '2ce11b5aee1bdd2f14eeb0f39a0232e4d7bcae73d07fe72f917d8a6668c663ee' model_hash = '2b832faee13a4885d85b811330bf787fb45fd6f8ad5798df0485e0dc262c2bc3' [crates.aws-sdk-codestar] category = 'AwsSdk' version = '0.35.0' -source_hash = '303d4970d866c85ea8d530a3ac2d6cbcbdfec0085b26c647751bc8d6738183ab' +source_hash = 'd7b2d1e08b2fd64f8f510de8caa69971ff290103923ea21ed2140f2a1d2ad10a' model_hash = 'c9a6612597a2e48003707036f12994ec6b0eaf4e39f100153647674b67a8c084' [crates.aws-sdk-codestarconnections] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e92f707386d68601174de2250a081848fef163907314f5324bf59d33b922a802' +source_hash = '3bf11981cda85e75636692f520db61447242db9476a4293c8df534be8cf2bd17' model_hash = 'f47ae3e13a0e6f8b1ed645715aa0f8fb5621821277b8250e87fcf6442ebdd8d6' [crates.aws-sdk-codestarnotifications] category = 'AwsSdk' version = '0.35.0' -source_hash = '76bed63f39e71bf4f989aaef6cf223d0b3810a2d1ed3d4f9bdaf948eff95b25b' +source_hash = '4fe16965fd0799ac781bc175190c4be03cafd65d3c93c2e8c650d69682df71cb' model_hash = '41e883a4dfd884874dd4c1039124b10cb9632c1bd91ce70a6ff6d7207720168e' [crates.aws-sdk-cognitoidentity] category = 'AwsSdk' version = '0.35.0' -source_hash = '74680a846f9ab65d2a57ca27c1ac653ba50177012511dbf028df0aee3e53575c' +source_hash = '1475bfda6fc6432b3f9c634e87985c9350ee6efcabfd4ef3d52e55e765298fb5' model_hash = '689dec3313ee2f31e1538895bd81f5dbcdf242ee3b8977c753e7fafa5036a940' [crates.aws-sdk-cognitoidentityprovider] category = 'AwsSdk' version = '0.35.0' -source_hash = '8d77696b7d8933a2aa8f6e82d81ac8fa3637a7cfb63e194965bbee563156220e' +source_hash = '708dda09d3971cde05642f2958c142fd064d9dcaa29d280645396f5cc88222b5' model_hash = 'e38e64f12c998c419d9da4a5b78fd44417f2bb69b159846b1ab4611a17ade22f' [crates.aws-sdk-cognitosync] category = 'AwsSdk' version = '0.35.0' -source_hash = '88f1e60eb92fcee6c473cf69ddb8e8f17b4e4ce2307ee1237af79fc29783c47b' +source_hash = '0ebba4e2840cc5373fa055f72c53687ef07eb6aef2f593eb808b7c0fd15de5cb' model_hash = 'af13ffa672d43db8d997a90a103b2b55b98f64cc5c8537e635c94194c37cfea7' [crates.aws-sdk-comprehend] category = 'AwsSdk' version = '0.35.0' -source_hash = 'af6c4521f3459e4af2bc025c4efc23f7ebd515ad594328ca9592e42c0a7a57e7' +source_hash = '7f6d2ae410889d001ec959402a3c14d5852e546652adfff388b366fd5a6386ce' model_hash = '79b40790833ebbf58beaad9999b2265dc4f8de27dd56322f4d0b281f1c639d15' [crates.aws-sdk-comprehendmedical] category = 'AwsSdk' version = '0.35.0' -source_hash = '23274c6a7b3773d08abd8f8d39f25364e08b47db3f4071fd4422fcb49ef05ea7' +source_hash = '4f167c7a99eb09295fb598029ac8e1bfba1702a45e521242ebe08358ed67eb8a' model_hash = 'b81682cd531559dab9989fe4a677f37e04eb416285824284c0514a03fa20f06f' [crates.aws-sdk-computeoptimizer] category = 'AwsSdk' version = '0.35.0' -source_hash = '84a32167f78ffc8f713029b960b6503824230030f8647f674c0d05a1fc341fa7' +source_hash = '72925734061382df0d70abb9e1f7d1f2fa420d92ac6720b0c5148496cf294b6a' model_hash = 'dbe7adba8339e43e9f458cbf473630ceae8bbf494abd273a4953be7fe2d01ac8' [crates.aws-sdk-config] category = 'AwsSdk' version = '0.35.0' -source_hash = '19aea250e26c06473fae64c38a28db5baf8061dc978730f26c8b62930fe971a8' +source_hash = '4946f59af8d52ad1a29810e61342b78c54b6c37f4cd6e69578d264c5c7e70895' model_hash = '3f8bf57ce622bccc2da7154ec1f898c3b423c66686a4100cd36d962576b95085' [crates.aws-sdk-connect] category = 'AwsSdk' version = '0.35.0' -source_hash = '3458ce5f09f1ed0c5164bf5249f78196e72458977fe9f84840d89c60863f2d43' +source_hash = '4f9a2bc8bdd8e6b9084ad030e84bae0e0a35c5e3f01657d9d36e2b2c1ea88990' model_hash = '3122fa3b8c96eea74e4e1055e815a973a5aa423c969f0ad3965b313d5d14395f' [crates.aws-sdk-connectcampaigns] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c1f89567790b33f86c8150184deaa11f6869c108f1902e1509d6847684f08351' +source_hash = '02c59c97383fab31313bc76718251a8b122b8a48062d0b08c503f420b51ca0dc' model_hash = 'c7ba772b2739f9c53eab8e090f6c20a8703992e0514bbe0a640e07c402695d75' [crates.aws-sdk-connectcases] category = 'AwsSdk' version = '0.16.0' -source_hash = '39078aada131baf3e671738c669e2cd6e92008c14a76d374e75224b5a87e60ce' +source_hash = '2e14a06fcf7566417a43fecfcf564e1d3b3be5647ea36c1ffc966a315e145686' model_hash = '52ab6403b67e8eac15d7f64744e78df588a2cc5412379b0f849d451aafce77bb' [crates.aws-sdk-connectcontactlens] category = 'AwsSdk' version = '0.35.0' -source_hash = '75cba4d27894d91ed35cc729530963f1f65b57ad8440b29d75ca20b782a7d274' +source_hash = 'da6a1b066510f75f494ee8b7d56b54f0a6081cc1f311a13f1368c1833e544f7d' model_hash = '7d7ccd829ba6b9900a61d00f04dfd15c10dc1fe6e5fef38e3f247cd995201089' [crates.aws-sdk-connectparticipant] category = 'AwsSdk' version = '0.35.0' -source_hash = '466de29168d8d051613494cc630d0b5b527b7fbfdbff0f85e69a266ed6197141' +source_hash = 'fe136948c40afbdda00d6aeb342f9e6ad294fb3b13a4c21c8733b45df1f2d918' model_hash = 'e53b1d854c90bb933ab1bd28eec7b69a3ff9a5f50875bc59be3e84cbd3725eca' [crates.aws-sdk-controltower] category = 'AwsSdk' version = '0.16.0' -source_hash = '1c82e36399b80213f43a20049a5f52c427d0158680a6784b81af1cf31eba8ab6' +source_hash = '9671b6551d57380a7bfd9b86779e6f8390c71e9eeec5ddfb815c1cc7ac313953' model_hash = 'c5c1c229358dc9000a7269f3d31fd1fc621193c6f4fb77aafce6528bff1efef4' [crates.aws-sdk-costandusagereport] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ed88ab23d66482a1735c2b31c905f221128f49c9ed41e8eca19c10b2828d1b1a' +source_hash = '3afaacdd73a09dd0df87494405007e9cc740785d744ee17aac96c8277e1619b2' model_hash = '109ccfab8c2c26923c9dd5f7dc7fcb0ebff104bfe6748e466ff002f963833dcb' [crates.aws-sdk-costexplorer] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ec3fad736fd46007a54b5a08ec743537fd0069681b8d8dd69143c8395d5c3b7a' +source_hash = 'f5eca7c5ddc71b8681b06a26d426d6cdac66680c6833bd3c3a6355fdf34dd6de' model_hash = 'fac03f2e28d99827ef15b3eace2f29efcc7477637fbe483d8bdf0bab775f1368' [crates.aws-sdk-customerprofiles] category = 'AwsSdk' version = '0.35.0' -source_hash = '317bf9fad5abec3cf719b210926e1ac32720e47162bcc5b213667fddc37db5c4' +source_hash = '3cfb53fc6a07567b162c79d2f48e37464fd754ea65f7678ce1a734c52ef6213c' model_hash = '6a521a06b219f60ae08b9dc236e73c3fa820c79e5937a4308c4be849415be53b' [crates.aws-sdk-databasemigration] category = 'AwsSdk' version = '0.35.0' -source_hash = '4bb6ce639345f90f1093e61d8219565e94d9b41165efc07313a493fb072d261e' +source_hash = 'f6dc6b8d7965ecf84c9dc477a89953fe2a0fc2dde9ab90c7b48fc7993e9a096e' model_hash = '41f3dd16ae28bcdf8fe94afbb833aeeb75bc5703a87be23fc8807b121803cb57' [crates.aws-sdk-databrew] category = 'AwsSdk' version = '0.35.0' -source_hash = '39087f19abd8e46b545a5b47ca66b4071962915a3e04451b35a823b0d5391e4d' +source_hash = 'a39c6613d6647ef433f1ad81c6779b1df1e3ea1e09af7286f130101bf7c9f685' model_hash = 'be1b2b6b61f567d2234f7f1d8af10e0828f59498bad2f47c3a2a7c0f7f045256' [crates.aws-sdk-dataexchange] category = 'AwsSdk' version = '0.35.0' -source_hash = '4489b3d9c03d7a0935024db4ce2e7a9268274513cc094746a9dfc81c67678dc9' +source_hash = '36dd7407fca4557f6786b3f89e2fd1f9d7baf09bd6d157dc6b29b4c7961693d9' model_hash = 'fc12283693c038f417716f6170b7640da3a5ffa54ea7d2b8b1fd53556d1c4233' [crates.aws-sdk-datapipeline] category = 'AwsSdk' version = '0.35.0' -source_hash = '70691b06ff166fce6d2c32496610a26b28b38d73c7f559fec7767c6629c5eb52' +source_hash = 'fc03ad4b47dd665b995b908d05108aa8e502ae6ce96c0d2ae7017c748423b4c5' model_hash = '481a634abb604c1cff5824bd15503ce726661dec63a755e44575bb41e20190d6' [crates.aws-sdk-datasync] category = 'AwsSdk' version = '0.35.0' -source_hash = '7416a920080ae7830266c5d7cc2131a421fb965de1fddd57b50fdddfc3c93add' +source_hash = '5d66a9f85b3beb82d13d0094d6f70ec4ea069dfefae3a435d61e6aa32a2f49cb' model_hash = '7e67727922144c13a982ebec1698c96fea98889a5b2bcce0372066deb40213af' [crates.aws-sdk-datazone] category = 'AwsSdk' version = '0.3.0' -source_hash = '0037efdb122eede382b02cda73de476c25f7e976e7c5d03146fea849acc1204e' +source_hash = '1193e0a4ba4b1d4ebae980d433778f5c8c960fccf362d097148ae3d7569c3c1f' model_hash = 'ca18efe373d7dec9cf86314a1e2abb6614802e1d0f6b1ac47e16c173aee7da45' [crates.aws-sdk-dax] category = 'AwsSdk' version = '0.35.0' -source_hash = '904ce5be129d4220e1f16ae4b0bd6eb06bd16004f57ea32810d7f34bb5419414' +source_hash = 'af89a0478d31947bbb156b3fb23a011afde31032f8034e2caf9d10b4e45974f2' model_hash = 'd7e14b3d73a945fd26374cb4679d329da7495f9664f9add2a2b129d431b1ea6c' [crates.aws-sdk-detective] category = 'AwsSdk' version = '0.35.0' -source_hash = 'befd1154b5fe4a6f77418203b8d0cd1b41a947d6bd9dcf6e71d2af86c2c57670' +source_hash = 'c4abb0de8ba1c85c0e72fb3c5a240ae04fa4c383db28099ae272c8e8a76aa452' model_hash = '68a6a8400f4013f8b74730e42968b85c759b734f1f6cdf4f7465fae0f480f281' [crates.aws-sdk-devicefarm] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f0a1585df92dad2293c35048eddd20c523104adc0bca8fd5fd60d4e153111c94' +source_hash = '469de1de5af6722db1ec1bd456b4d7ef632576fbf7d29f00552dc43191787269' model_hash = 'ec1c909f25359a48f8978f26ec7ede52356bbae980a52ccb03022cb9a202f1c0' [crates.aws-sdk-devopsguru] category = 'AwsSdk' version = '0.35.0' -source_hash = 'dfb0d6a6aa2ca68f2debf51274b266c2f68fbec29ffce58686fbd6a49a07e7ce' +source_hash = 'bb2a364bebe4ab54300fb14b44b305b1a3a0a327167ae64400aeb1875d6e2e02' model_hash = 'b3acf0a59884b7504ce6f196736993338aa9ea89ac46237d1ed8beaf31cc50aa' [crates.aws-sdk-directconnect] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f0905a0383fbe81db7114bed1f6e3939a658bc77daf41139f6fe09695e709eae' +source_hash = '296e580b88253ac59dded3535ff7f6c83b9b1241355234f5f54826de9d70ebe5' model_hash = 'ee09ff752dd802c761854b097d6ad968cfdccdced89f765bc2cfe1714bc7c2d2' [crates.aws-sdk-directory] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ca48ef30f86069499300c32f28cc35a21db0da309a7567e1dc94eedc10fd663e' +source_hash = 'faf517feb7f08339dddd326f9ecc795d3b87b10943717b2e1846117b46252fc3' model_hash = 'a997468080b0ca7ca2da1c7b16d6368cd90b40ac880cef2ef2e3b683bc3cf6fe' [crates.aws-sdk-dlm] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd0f6908b2eb7b4103e7217711a5d358047059c063805e9f49a589f2d1150bb3a' +source_hash = '8d7c52e5e8a6dc16f85d86064c70fe2b361bd672e7baa5be31077aa302427c87' model_hash = 'd2d138a17a93ec90b0c66aad3f479a3c5b4408861cb3c2ca2e8dff2ff858486c' [crates.aws-sdk-docdb] category = 'AwsSdk' version = '0.35.0' -source_hash = 'dc885cd91915279aeb45500bd8075af6457ba7de0c8ef5e9c8be534b52fae1bc' +source_hash = '07d5d8b0e44341c5a005936e4c1cd2648a433f245304b3312a322deef0f77ce2' model_hash = 'f9b5eafde1702512b9df980c6330e30f1b8bc3ddb563511e676a5706ac4fe152' [crates.aws-sdk-docdbelastic] category = 'AwsSdk' version = '0.13.0' -source_hash = 'c18a15da39123ba18150f0e28bfaa5dda2d9e3f47bc2a43c1c7537964135bc70' +source_hash = '8391e1bda93a809e292c9a219eb04242e38a3b970180468532248d761274eb24' model_hash = '2778fb1d2bd6f1db5c1dfb97599dec4c3e5cff69b1d28041fce78bca740cae14' [crates.aws-sdk-drs] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e843b0a48a7eff13698815d9f422564a9474cd6f5989d2184eac98b861d0fa97' +source_hash = 'd59e7960e949416f7977cccb51b1fb3c876c92eff8eb134c4dd45c16229c23cc' model_hash = 'b7f9befa55b9d941551a3ba7092a59f71b6a9ef830e89f2b8b07144558ab3f98' [crates.aws-sdk-dynamodb] category = 'AwsSdk' version = '0.35.0' -source_hash = '2ef47d16b005530fbecfa527d21602556ab8ca1904a5b7592d51c5f74428fc80' +source_hash = 'b818d08d5f256087979501a3acb444c554b8d569833de741a96a8613d3b0f6cb' model_hash = '0564720efaf901c5c7285633ff493a26d0851f49864f7bda56404b8deb32a517' [crates.aws-sdk-dynamodbstreams] category = 'AwsSdk' version = '0.35.0' -source_hash = '93d46007e747a677fa704f0d68c5dae5efc7cdda4c2e63bd8bbcafef0632f549' +source_hash = '190c5ed1cc8be7c5d70d36f82133172657d5509f385e3b1a14a2f35a3a96a2b5' model_hash = '508c489fe7138b1db4f13650f3dd7dcad2fe2a24e9ec7c6fd4dc56ec7b2a6afe' [crates.aws-sdk-ebs] category = 'AwsSdk' version = '0.35.0' -source_hash = 'b85f769ca1e113d711553adeab5a2fe81fbce49fea8a4bd644afb9346f46a42b' +source_hash = '8fdbdbff9e7b01830bb7af2957e4419f4bf2fed335a4e95ba5275f8b26f9d26f' model_hash = '5ec7004d46e2bb30c8d974da3846e960c6d52a00307ee4cc8a62b95566a1fc84' [crates.aws-sdk-ec2] category = 'AwsSdk' version = '0.35.0' -source_hash = 'eb96575a444a312179a9773c75da027f699a2e66c8452fdddae24037f7b42a7d' +source_hash = '7bf8938618877fc6d632229ae41adb4a6b7fe66b72520b2aa35f5bac95676100' model_hash = 'b6038457a3e1304c6039549ef32dfaa6156fb65186a318f82a349c49c019b419' [crates.aws-sdk-ec2instanceconnect] category = 'AwsSdk' version = '0.35.0' -source_hash = '1928c86e6b5d1cac0a97146148fb41d987bc6f5d8eceb6afd1785cae83a3f308' +source_hash = 'd7aa14431b991196020201a3c147c03a03502244c6e9a4bbffeba8cec70da129' model_hash = 'e31677598e0dd635baf517c7a2ed9ab9b321d08cdf30e2b3dbeae52d1b16dbb2' [crates.aws-sdk-ecr] category = 'AwsSdk' version = '0.35.0' -source_hash = '6afaad471f264989569d6d079db201d551ce7a6444bfbf88702f8cad1e6b029f' +source_hash = '50278df30cf3be36d5e8ddbd3cd1ef0cc01c34fac2d2c6e01f31bec1cd09ccee' model_hash = 'ce51d6ec11f46cfdb20811c09e25a2c4228e047c2047837bc7482de887a77b39' [crates.aws-sdk-ecrpublic] category = 'AwsSdk' version = '0.35.0' -source_hash = '9a5d3369b82c16a959160f2bc8be9b6f583ab604dbc9e61ebd49b9206725fa7b' +source_hash = 'e5d87a7da79e5e6851c8b717dde1419269860f4be5a1d1a5a0b2da912147a005' model_hash = 'b6e23be351cb44f9f2b57d80f227604694a8bac84ed1467add8d019c824ac349' [crates.aws-sdk-ecs] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ea3288af93551ed50001c792297b1498c5cb84cff15fe8107ec80d1039ebe4d5' +source_hash = '065ca92fa72bc5579f80a3ba102821e2d9949494e5e25da2adc8f8bc2e5588d0' model_hash = 'd6104d6c8e430700ef3f1100cbb20cde14368e503036262664656125c472eb4d' [crates.aws-sdk-efs] category = 'AwsSdk' version = '0.35.0' -source_hash = 'bed02326f6227bd3e23e8aff53071f6a1eb1637004fcb0b50be6a903faaedcb1' +source_hash = 'fe7e55e94a9d519e70052d451c7cc5e1460c3085eda4740abad02e76c3976856' model_hash = 'cd619864fc99b673dc23e34fd72890b801af9911d34ca947c9d2f8cc4e898fbb' [crates.aws-sdk-eks] category = 'AwsSdk' version = '0.35.0' -source_hash = '58ea14e35ac175cf1d5ebfdd617b59c1eef5596978e6f5f5bdb2f2ad8708b0d3' +source_hash = '1eaffccacff1bdefbf83eec7a3d3129fc8171e36a4811d1614e757863bd2a455' model_hash = '4eae836fdfbbc851364bfde366e12e5ec01a2550763bcd5ba3f16df776b31692' [crates.aws-sdk-elasticache] category = 'AwsSdk' version = '0.35.0' -source_hash = '8f9595a6b20e09efbd950916f48978b16ad0f4f6d5b95cf83433e14912e60892' +source_hash = 'a11c8859435c9efde783ee9ba8e26182ae6cc760cb02a0882dee4591b65ae1dc' model_hash = '98bd37d6e125e4d432ebb6acbfa500f2bd22cee579cb5328f4e648a51915c59a' [crates.aws-sdk-elasticbeanstalk] category = 'AwsSdk' version = '0.35.0' -source_hash = '9069b78f3c28ccf0b75d617a8deb699d67362404ae6c06cba686172da123ae88' +source_hash = '26ed1a06b1c832eeeda157daa8b5fd55823330dab8803ab3827bd3ff8c9a9638' model_hash = 'c2a1a97d61151c9e55e064e5be174f1331ef93916f1eeee081561ad794095cbb' [crates.aws-sdk-elasticinference] category = 'AwsSdk' version = '0.35.0' -source_hash = '2c356766a5bcefd42e1e87c985235e8d1aac60cc44718c8f451616f81be82249' +source_hash = '4cfc8a9b80261d9857800885ce9ce5740d20c880eaec1bc20c00227027bf9471' model_hash = '237abbdf572e7a7a4fc9891f05db5f8c0664c1c757dda0d6ac4707b88ba5e120' [crates.aws-sdk-elasticloadbalancing] category = 'AwsSdk' version = '0.35.0' -source_hash = 'fe71e057a407f5d811161f4d3badd15df387a7a30e38849fbcae8a0654c00188' +source_hash = '1aad273454c18c1a34ff9950b5526980880c5c32e1b24c5e018bcb38c366a20e' model_hash = '1a7d5d6ed38bee6ff2a4358ef2d4c7fc4702054beb96a2b03d8b5353fa3a508c' [crates.aws-sdk-elasticloadbalancingv2] category = 'AwsSdk' version = '0.35.0' -source_hash = '943d1cf859935e019f3e61e27cc7d6ae879ae8ecf4a5c35af357fc0340ca8829' +source_hash = 'ebd58681356206719593cfcc4a4a6d81948bb8c9f3a5eed8323cbbf2e87cf8ca' model_hash = '86e2e710c021a56bc9743a708ff3e83e25ef9af1e39f87f13b243a49f9006a0c' [crates.aws-sdk-elasticsearch] category = 'AwsSdk' version = '0.35.0' -source_hash = '4a7c8e2f61e6ac1c445fea02d4fc73ee0b85e306dd9f12908dd028c1418d968b' +source_hash = 'a949945e7ad7703bce75998e87a3c15a333f02f4b3cabe70e8c881a2fc556b70' model_hash = '05de42f66c4d7598ef20b1faa75e84baa93290ab8a2c78d0cb287e142225a05f' [crates.aws-sdk-elastictranscoder] category = 'AwsSdk' version = '0.35.0' -source_hash = '0e034516049faad613b211efc55a89be56eabe96e7c3b3cf89b30cc0a3a8255f' +source_hash = 'e69bc0f9aed21006595d04f2900a8cfd16f939e2aa6b28daf6c0fd443581e304' model_hash = 'e8bbfc6dbda6756c8b10c86959b1e4c2abb3d79d65dc3fa547854ecd77fa7a62' [crates.aws-sdk-emr] category = 'AwsSdk' version = '0.35.0' -source_hash = '39ebf77836c7a254ea0140ada6e7200753eb3d0fd41cd2712f9dde9d2e489880' +source_hash = 'c89cf4b95f9e6623ff7a7c1db25f68f607f60228ed62a046e60144c70ad2ec3d' model_hash = 'dec559efdedd26ce77920e64a043be7c74dbc3830077b18ba0bfdd69323d3eb5' [crates.aws-sdk-emrcontainers] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a55144433cd72e49d7582cd85ed8b863e4dd9eaafc1518fd5437a19abacb045d' +source_hash = '4aab0326a3cec3b632c9eb8627fbdc0e4ce943c80c385ed297e3705d2ac80adc' model_hash = '0eddd3dab59667c5866f7404605d386ecff1e7080ba1fe0a444c8cd2abf50f39' [crates.aws-sdk-emrserverless] category = 'AwsSdk' version = '0.35.0' -source_hash = 'fdb30719e4acc58638b9dfa9c223a442c0cb601985073b7c5c79c2e967375c35' +source_hash = '5fecc6fba11976203ae4e09689e010f5ff3f16a84ae746aa508f7992625b4bd3' model_hash = '6fdd5a8b3343b75f62ff3fcf8b8f3babadcbbd768d85394408bb33c569b556dc' [crates.aws-sdk-entityresolution] category = 'AwsSdk' version = '0.7.0' -source_hash = 'a4edf35ba3cb72a7c3624953467b17386bd3cb26458389f5d3dad10252632871' +source_hash = '19abd4cbba30bbf3057faa040fa1d9ed27a91f2b681e73124db384177fa0fc8c' model_hash = '0888138213bf6be80dcfcf6368e503fc8374356f99b26499a6047f429ab2a3ee' [crates.aws-sdk-eventbridge] category = 'AwsSdk' version = '0.35.0' -source_hash = '5c487d22e4ee0188fea9ae0280fe69e6e87514af4c7e76ab0585dab41f04d4d0' +source_hash = '3ec257cfbd606dd7d8c827b404e143896338cc07229a080e4410deae02643d94' model_hash = 'e36d9ef92743b7741581702668e37296dd7cc0c36ac6d06ab7be6ae489271062' [crates.aws-sdk-evidently] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c578c58b3693c633f8ac8102cbc84f3d4a9dbc52e2e8183591935d5f62ee74aa' +source_hash = 'dbb6fe9d74d28056b9f33bc44d0ae933916788818a733c39b451fb4bd9e3ebc6' model_hash = '46ccb563d968d97801d539b55901e369c43eb44ec86ad0c6aea95ae44317eb44' [crates.aws-sdk-finspace] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c773b57bdff61d8ec66786a56b0c59ee50e0412c57e9823178dc64056f797657' +source_hash = 'db83688699fb135c12c7d9706b5c7309df8259f611ba6ab9519c119affdfc6e5' model_hash = 'f4d468ed1c8f4fd87986108162ae379cd662f95c1253a7aba47f65972f91837a' [crates.aws-sdk-finspacedata] category = 'AwsSdk' version = '0.35.0' -source_hash = '456f370f87fed7226a09d1d2de721f07c95c8a37f2cefe094c9573d7b2e54046' +source_hash = '6974a7e886753ff9e8ca4e25750bdfb189b45142ea655f007d1676098ca8fc54' model_hash = '92cf8f6076c72482806a51e1f70294d72359f61b310e913516dee564d5fd4f5b' [crates.aws-sdk-firehose] category = 'AwsSdk' version = '0.35.0' -source_hash = '99e5dd5533dbe6130c5ae196bf7648b730851550d923e53c21064d40440a584b' +source_hash = 'a7e95ccba0888e00b192f998ad095fd21816bf0c33e822276c5327ae9c20f39a' model_hash = '8c8445127349e8e30d94b8518f1972b2adbe715a27cbae15004a382f9aad4e03' [crates.aws-sdk-fis] category = 'AwsSdk' version = '0.35.0' -source_hash = 'be16647db6e0f7bec2e34066df161770d1d943cadb814a5b2922c91afbff038c' +source_hash = 'eaa436a396ac2291d61a33ecb8b10349cce158b85ec91f74b943cf34c3bbb595' model_hash = '5336e6a335ef0ab601d8eef64f9a27ef6ca69f780e78250e175fd2292263fccf' [crates.aws-sdk-fms] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a15299a6e1eeee9d310899c6fb6f4b307022564bffe6846b913068df22aa8272' +source_hash = 'ec9a26f73a1c76edac2eebe3b03fad7627f26e83435cea2b88079f9894fa5175' model_hash = '79a94b8dd567fb6da1f9efd5f861bb7b093751ea8a6d2ed41d69c341ca8a5a23' [crates.aws-sdk-forecast] category = 'AwsSdk' version = '0.35.0' -source_hash = 'fd2c0fd394d911c764a939d11db5884e9966742206858beb75f48a00b47ff508' +source_hash = '78579bfa3ca7e9f5e7036f0f38be188f6539460dc9fa1e9b73e9042f6b820828' model_hash = '3c92c6c2c8844f08d25fd063a1ccbb94f0ab0ea0f1c1c3469adcf7c870d8bfa2' [crates.aws-sdk-forecastquery] category = 'AwsSdk' version = '0.35.0' -source_hash = 'b213e4997a5c9e398201248f08829b3aab44e72d9f5913f18ff5ee1673063661' +source_hash = 'd01fc04bad757308fad1c9106d4efa1f9cf420307ddc98cf37c716ea396f5058' model_hash = 'cd74ffeea730f02e0805832659d2d88713e61d588faae22786d41261205841a8' [crates.aws-sdk-frauddetector] category = 'AwsSdk' version = '0.35.0' -source_hash = '504b1e98d90f9a24b569be384303eb5245b7402330858049e4ade053424f49d6' +source_hash = '6431c4d34e7100ea1af7c5010077a0554044e3551f90abdd7bfc19da83514f9c' model_hash = '4a429ec61afe2d8f7f9acea01da3c7a57bc65443c0f93325600ae2cc58109084' [crates.aws-sdk-fsx] category = 'AwsSdk' version = '0.35.0' -source_hash = 'eef1002c70094d5f4fd4cb6650d286ec3cbc6d01fc96ef60d217cb5d5243f769' +source_hash = '44c7b5f8f40aa36b73edbb6e0612a3b5136bdb017679a7f03ea127b30b8ce115' model_hash = '27bb3e2229d115bbd0627f8d6126b07fc709150a40f101ac5920c66756652c46' [crates.aws-sdk-gamelift] category = 'AwsSdk' version = '0.35.0' -source_hash = '9b970d259e3f09d42987483b5739bb0052ef7683669483601aeedbf46b434d73' +source_hash = '3027d1c7be90cc441c742fa76bc8e801445ab824d718cd599454517db5194dff' model_hash = '27b0e1433b7fbb9ae1617110bcfceb5dd1de40a095072b804917977d0045b00c' [crates.aws-sdk-glacier] category = 'AwsSdk' version = '0.35.0' -source_hash = '79d75f11555b8825eea61e6a1b45869668c4bd5318da415d605c6a2adcd485db' +source_hash = '2a3f70508d8463426dc5f977bdba6484060903e449d1ff91f95b9f4c2275fe4b' model_hash = 'dca44bc00b97fbb20fbb7412538d6aa5f7ff23a66ea8ff12693cdd6c869ce299' [crates.aws-sdk-globalaccelerator] category = 'AwsSdk' version = '0.35.0' -source_hash = 'aef6979c7a8d9d621574cefe3b065220d51c93a6d49195ebc235d5fd88507890' +source_hash = 'fafc6063f6972239580c7348ca0038c10b0298f7cac0a6b8fd2d4cc52f3bef6e' model_hash = 'e013edeef6ad5fee63611fa639d82f17c17fc72d137ef35cf7b91e117d8efba0' [crates.aws-sdk-glue] category = 'AwsSdk' version = '0.35.0' -source_hash = '2fa645872a14d1834cac7cfb4861832dce758e8fc1de3e24a889308da7df24bc' +source_hash = '62919ee69553e82a77966e6825dfbd10ad65bfa79a06dc6366d29bf9c2942839' model_hash = 'c0f46663caf23f32254722fb2b569ebf7d094aacd3620ed7d4b522cd54a010cd' [crates.aws-sdk-grafana] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c42de97099540a2d7cf91fcbbc07cbb2cb696ccc242c3c4a39008d150eecf020' +source_hash = '5a5557ee9e2dd6d4cf88fcda8c6ef69250b2ae4a24c8a04ebe02a273eaaaebbd' model_hash = 'dc70e3bb26307408e3d08099d821451db15863a6323b35bd634172eb06223296' [crates.aws-sdk-greengrass] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a761cb738bf1f1b9cea04ef2c07986b54f62a399d0d02afe56ea4ff132ada318' +source_hash = '64ffb3360ec28646e7e30f17a573e6b54cd4465330f647e447706732304a41b1' model_hash = '8f3a10c55aa9df63e30165c77677ef2e9648dd03d3cfe4105750a626c83a22df' [crates.aws-sdk-greengrassv2] category = 'AwsSdk' version = '0.35.0' -source_hash = '9498365ed6f685acfeddbfbe3865703ddbd5014275b0add6971951b1d2d88cea' +source_hash = 'd93b51c50f948856727c5238dfef97f63782ce0d2394728e4f714c1f27b728a2' model_hash = '518ffdf7f9b2a5d2e1e1489fe40697b01f26fbcd5b19c3492dece6afa1eca6ad' [crates.aws-sdk-groundstation] category = 'AwsSdk' version = '0.35.0' -source_hash = '1b8b6a89b8f24f19dc198d70ef6a1ae026721e69a6110149ff3aed5b8761adda' +source_hash = 'ba2aa610447dc5d88948233432f9cfa2f0832dc4623450ceab11ec9e0ec9ce82' model_hash = 'e4806ef293b21cd0082366ed25a3cfc1ba9764f2b425646826c723327fec0431' [crates.aws-sdk-guardduty] category = 'AwsSdk' version = '0.35.0' -source_hash = '6a56fc99b3c495bc9b034c3764a853d1b900de95dd42a70c42dde42725573555' +source_hash = '357da7dc01a0de6c931caf9764a1061e9ceb5cc0f0be59db0ea1cf50b4df5293' model_hash = '4466a9db859f86469e2a87088762168f065021c0a252a0a8df132ca742d799a5' [crates.aws-sdk-health] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd6c4ef7e3bee8f39d9dc214451f0511b0e8d16e30d66a564f3d2bdc3fb1bd68d' +source_hash = '45053d303243cb8351e8395b60efc3f7a8ae04c6672572c726cbfa1cc2b3648c' model_hash = '007f1728e05ba8197e7a685d6c4b9708ff63a40ec20a2ad256d12a2d4b022664' [crates.aws-sdk-healthlake] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ad02be880039f7d2d8e91ef348c13908f558f1341d73492f2d66493cee102d78' +source_hash = 'aa6752a488d7a25e358d66863f363da573327b763068ac8574c49afc75e71f7c' model_hash = 'c017eac7446db64802bb8867d8e7e0198b98151252bdaaa7bb9677f89360bcbf' [crates.aws-sdk-honeycode] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ed806d9d5162cf512135bfab397de9550abb29ed0b431960ce851303085bed1b' +source_hash = '8d9371d4b522589c18f07e9992046d4d1800b1f6d5f4133bd65d47f768161e2d' model_hash = '2574f912143346bf583805c22ad4ed6f2a93b08bedeb884bac73ae96c245338c' [crates.aws-sdk-iam] category = 'AwsSdk' version = '0.35.0' -source_hash = '628c0dc0a7dfd04a0493e65218d04b361b5c883afa7db3776e6431c7f85a5a6d' +source_hash = '6de70ec0bdf56a41af6fa297f147ff8159986ccac127a246b14093ba679aec3e' model_hash = 'f72d481071b7640b84c01d363f9541680e1e8824dac0c01da0d0bebbe715e18d' [crates.aws-sdk-identitystore] category = 'AwsSdk' version = '0.35.0' -source_hash = 'be1c602dc5808d3a643a2df828e1cc444ffa601d5a90bdeeccaa42b0c4291058' +source_hash = '9eba87c6143a3335a2dc9769df3219fbec3773aa77e097cd43b33b7b42f7e161' model_hash = 'abd0728cd0c7060cf5e676f42e09b2a177eea6729e727c62b19b84e35304f7b2' [crates.aws-sdk-imagebuilder] category = 'AwsSdk' version = '0.35.0' -source_hash = '1ee18b7a977d951a66e2c2df09f49b9ace6be32a9a8b4d7e5b9c3c0f3bf8dc24' +source_hash = '58c0c5e4b63abd3b5ff13c8f29096fc0b01759054ff79f4ebd9366b7253c06a5' model_hash = '1708d88dfe0582d670da353ebdb86d11bdabaea78272da7d4a11e8485fc5a41c' [crates.aws-sdk-inspector] category = 'AwsSdk' version = '0.35.0' -source_hash = '588880d159f840b50223044a1cf59a41d63c93c6319bffc70ec028d82a9ab9bd' +source_hash = 'bc02a28ef225f30e1dc8db3715d76ad24d6bc07392f646ed84f62a6275013952' model_hash = '70886218ed0115b5c85b366be76a361d4b27fa844847e5a2f902cce0b8f7ba5d' [crates.aws-sdk-inspector2] category = 'AwsSdk' version = '0.35.0' -source_hash = 'de7ce8374b69820c756888bb339067f6ffb4fab91b686d91a59603fad80751ae' +source_hash = '84729a6a0b483162bd930f23f331d83c593bf25f7060b00b00eec1100970203d' model_hash = '640728f635deca63875e474a1517dad59d1b30ca20fd44f753c2adef4ee61a05' [crates.aws-sdk-internetmonitor] category = 'AwsSdk' version = '0.11.0' -source_hash = '7710602c6df85d26c0881b054c784b3ef444698932e8cac1b146d8c9ce098446' +source_hash = '129ed427d0a2c8f9a780e6055171bb7ba0c5d2f6562352c402832984eb8077aa' model_hash = 'e642ce2b29fe92c5552c49eb0a7ba532708ff056d76bdca4048638cfdc43b3be' [crates.aws-sdk-iot] category = 'AwsSdk' version = '0.35.0' -source_hash = '9d5ee4028bf271e3a1ae01a8826c0cff9ec46f7a607698d4b0cd78497abe6cf9' +source_hash = 'a3715760db4f2b16ab96e4628a61075279224b73195afd66d787588c49343383' model_hash = '402b4630d4c21ca55e0edf3ea3fcaff287d4e7a0cb89cb54e4831c3c7954f30e' [crates.aws-sdk-iot1clickdevices] category = 'AwsSdk' version = '0.35.0' -source_hash = '2d9d5213415a81e3c0500fd6c49d39914dc71243948fad05cf56a16875f39191' +source_hash = '28698929a866921a00ff4644b3a8cf39334c775e9fadaf97d0ba662d327663e5' model_hash = 'e93cd40d38ef410280773561dd132f8444af0624521002cac3d75add302e2628' [crates.aws-sdk-iot1clickprojects] category = 'AwsSdk' version = '0.35.0' -source_hash = '5aca22c8f000f0856d1780a39f23a50b093818a4a8974370f4f3f804a4b5a5c2' +source_hash = '269350929fccf0db41b513a25e06b7dd47ff206a6b90c5c13fd4812f8260c87f' model_hash = '405130e1bbe04f96d330ba7b447a87a23cfdcc8e8a7eef724327e3c2567e12bf' [crates.aws-sdk-iotanalytics] category = 'AwsSdk' version = '0.35.0' -source_hash = '122f83473917efabed913ff4e2648b04dc42aeebe62d1f42d184df628007a010' +source_hash = 'f0fafbf3190ec5eb1ec38cd7de66c3a22692c1c90db834bcf3deb011a0184a68' model_hash = '8b7402d76f582f5fa80d28816367eb766bf53a7d78502626ed14defd1943e0fb' [crates.aws-sdk-iotdataplane] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f5d096070b83b7bbb12fbe648a5fd0c1a905b9fb0800d3168fef0112495d7e00' +source_hash = '74003b0eed76720321a1c3166c85a155c714a0ea0fa7495a38979a50e797b7a3' model_hash = '3b983cfeaff668f43c046ba541674ed11c5466da9ccf7044b85f01486ce73abe' [crates.aws-sdk-iotdeviceadvisor] category = 'AwsSdk' version = '0.35.0' -source_hash = 'fc92a54656ea3e22f954c68a4740f043c8a9be51074ea6f3f60af92f8d3865cd' +source_hash = '92a9a18620c7e36ea477fb4ba24b84a014686d44915da54f5173a256302970d5' model_hash = '7be5dd5e9fd40e46b9ab4fdf2655963da6729535f754531ce5a9b85770eae65f' [crates.aws-sdk-iotevents] category = 'AwsSdk' version = '0.35.0' -source_hash = 'aed302339042f961fa7a7ec42d9b3a9992f3e447635401079c2a55ec4c366594' +source_hash = 'f4fb1aea78064dc7cb8a23a0da11269f21115ad531866c5b7a0e3a9927e4dff7' model_hash = 'adc4dd4b934e56087fb5d3b74f5c21c0819f6f93c2630ecb8c6dbea7f3eb4c72' [crates.aws-sdk-ioteventsdata] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd0dc96e197d5412dcfd1d58608bf165f3d402b35e8cda50ba687708be9bd1711' +source_hash = 'd9628b37116da49ebfaf11323552780d8dcd0afc1983ec12738432d8a3f49102' model_hash = 'a492223e4a57806608f4d604075e4b24a6704eea1f1cad70cb9fc77c9f04c9a8' [crates.aws-sdk-iotfleethub] category = 'AwsSdk' version = '0.35.0' -source_hash = '756e47a636d27744208e434ffd330c768be10fd97dd61e01a9b04e0dbe67a581' +source_hash = '7286ad015f6559a5b192e5c5fa61fdef3f389741954354e3cc4892fae5dcb3fb' model_hash = '9281144ea084bf846594a5f1a936ebfe558fffe20644894561c427dc11db30a1' [crates.aws-sdk-iotfleetwise] category = 'AwsSdk' version = '0.16.0' -source_hash = '170907dd2bc3e1046a4cfefe17d801c46cc7eb8548d14f4d9b5dd55214be14d6' +source_hash = '4372c0a6844ac9b187ec135b3161043171af7da5ce2530c2075d72a96461d956' model_hash = '21aca50baf4f057010d1f1e98cce84feaad8be7ae09457663c45b619976aae2b' [crates.aws-sdk-iotjobsdataplane] category = 'AwsSdk' version = '0.35.0' -source_hash = '861362c48f081b33bbb49beee80016a6e1181f9804a55675c845014d01542f18' +source_hash = '3e9f9ae6d9a88ea5a70f81645d2db047f18c10e567ea85b4702922f19802bb5d' model_hash = '3d077de4462602736c84fad7a2296c47b72b438bb462f5fed750378ad992059e' [crates.aws-sdk-iotroborunner] category = 'AwsSdk' version = '0.13.0' -source_hash = '251b5b1ca665d610018f7f55fdf92908c9a5d9a61e88df5a6834a66676294f8a' +source_hash = '20715832348f25bb8f6c4ace1d8dd7481803f77d0a1e9bbb2fa5f074b4dae861' model_hash = '513e793b66ba6389799134f998489dd2c3fbe723550b5de7e0127121c971a071' [crates.aws-sdk-iotsecuretunneling] category = 'AwsSdk' version = '0.35.0' -source_hash = 'aff7715cf18dcaf2d97d4143cd7a8fcfc5f8e2c6918806bcd7508ab6493164a2' +source_hash = '79a9eeb223514bab6f635d9e8ec29a73dbd602337e0015631be0018a83eaaa71' model_hash = '260b1b95d87fb1ced3c57c054ea243ea803537b1e73b98f1db9f47a913dc185e' [crates.aws-sdk-iotsitewise] category = 'AwsSdk' version = '0.35.0' -source_hash = 'bdc8278bb2d1087e3cadcccd171aaf80c67bd921db6725148d03fc5a711dbb92' +source_hash = '04a562ede418b7ae1b9ac751e54b352655c19960d120f37fa52af23af7b5c39d' model_hash = 'f3c076fab82000bbfd36260d48bdcaea88609cd99c6b40fccaf375c6f5ea2dd3' [crates.aws-sdk-iotthingsgraph] category = 'AwsSdk' version = '0.35.0' -source_hash = '9601a844eb3415cf2e079878f379b0b52b803d17560bdeb6104ff3d7dacea5bb' +source_hash = '1d7a779090a4f2e5a5c6b95135305abaf0bbee612838370fa0ce2396f8cde970' model_hash = 'd6c9b8a53d9eef739f2a7aa03c80b5bf7d572b551172dabbd429d06975d9855b' [crates.aws-sdk-iottwinmaker] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f2d1674c7680e4bb7f952a5eb035e817bf5ce0df606ccf471225e00f46e47d02' +source_hash = 'da5e57bf6b306f2a0825e8b0b7570dd1e212acdfe1b2682527260ba71f74607f' model_hash = '1dd6d376802e5024754f82a2c36806f987b9318634a52b2da5909d03524d5f04' [crates.aws-sdk-iotwireless] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e13f49c4f70ba5cc9a8979384e753f0edc38349d448330bb4706f568f393b5d0' +source_hash = '670c35b058e9630e6a0227f18c22d1acd021758e88782ad775a9cde3ad0f3761' model_hash = '029ec945dce29cc1d85b8924f3a1e558af960da9f61a37f5828b0502a3ea42bf' [crates.aws-sdk-ivs] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a442dd2281d0d48cea62a688beb1e4d69a4cdef7d78e2c75c72dfa20131dcc57' +source_hash = '29309e109d4933ad1660a83041154f142d170f947eac82ef5fe141aa4836e9d2' model_hash = '02ed8d777298370dd1beac356e286a3b1267fd1ba924f315ea0bc9a2ab7fcf48' [crates.aws-sdk-ivschat] category = 'AwsSdk' version = '0.35.0' -source_hash = '8a5f2548e6a50f0f8123fd7abb99c691a4088053f28c98a155bcf01a294719c3' +source_hash = 'bc4bcd0bd881da94d3aee34e0b3b8a1d146f8060d9ecf7edc1397dcafa2a3fca' model_hash = '00a0bf9908293f78008cb6a8efbdba77907ae99ace697adb4d592bc8e5acdcff' [crates.aws-sdk-ivsrealtime] category = 'AwsSdk' version = '0.11.0' -source_hash = '2b2cf8abc7fa4f20f9bfbf376fe32c0d77555d5ba92afc36ef965df9baceeb25' +source_hash = '868932810afeca8c6e1c8491933c1cd6f43cca2fffbb3f5aa127cfb3ec2585be' model_hash = 'f43c930acad97fa85b7c54aa1c953d89e3977191ebe0189186dcf74711f3f587' [crates.aws-sdk-kafka] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f16682e4b19988a23e8b872ec7dd5bc10697ca399fca52280428eea0c0a7c04f' +source_hash = '10f97b8358b6b2ccf96cd1c2d42be9e7dff94a7834cb402232790847af372b3b' model_hash = 'b72b984818e3a0478ee3756297ea12684dc0a452885770178806b82ee0612461' [crates.aws-sdk-kafkaconnect] category = 'AwsSdk' version = '0.35.0' -source_hash = '2275d3cea0c83986ae3f6c7400291aa96fbc2ff3e1dd4b85d929648d2cd224d6' +source_hash = '1715e65dc7bc04e1c9463d632e1ef7f3ac5b7e4aed05c4d28616b463e01e7e4e' model_hash = '7494a1d2eff837117e2eb6982f0922c2372b0f092a1a28c4ec892788ce768289' [crates.aws-sdk-kendra] category = 'AwsSdk' version = '0.35.0' -source_hash = '762ecf8c7ac84ac93ca0e79b1da1c708809baca67bdd7615fd2f4c6f31012e82' +source_hash = 'b21fb5048dfa6a1b4bd46ec143a3aabab789f1357760ddc88a6ed654a8dd48e6' model_hash = 'fca62a1bc0901823f895b0fca061c4be6375be4e1025b9255bd9f837b01b74ae' [crates.aws-sdk-kendraranking] category = 'AwsSdk' version = '0.13.0' -source_hash = 'b421408a70c768bdb0450bc4ba30304e29ee3de36ea95181af4036764dd40cc3' +source_hash = 'b582734c9114a2683443ea8c70e38d8c01bc599ebf31354c0466625098a942cd' model_hash = '1dc43d3164c0d60b6fff3ea824b56a6e5213bb665812174fa1754dc554bf727f' [crates.aws-sdk-keyspaces] category = 'AwsSdk' version = '0.35.0' -source_hash = '186dd5d4ea8f5312fd50aadcd7cddd9ff9109f778ef58ca7dbf82835c853e05e' +source_hash = 'cf6da8c14ffe88f08b7d634467efc4633f0e3b0c6fb2b5575f8a15a72e2a8b0f' model_hash = '88d95b541acf3c316f9a288941ba231041c2a348264dd853f7987bc47342f4f4' [crates.aws-sdk-kinesis] category = 'AwsSdk' version = '0.35.0' -source_hash = '26b2ad677bf7aaa9e3608a1e48ca20ceed127dbe55ca16d78b0d7f2e54bd4369' +source_hash = '8a3bcd29f6ad4079f31e8bebe76d6c8baa0753f6d67494bde00046a77115f5b8' model_hash = 'b9a2a9adbe811fae3c6a6740f78dbfb5a6b41993abdf265b532e820d59802711' [crates.aws-sdk-kinesisanalytics] category = 'AwsSdk' version = '0.35.0' -source_hash = '3a9ce668c79bc0ec139ff40d71abb3f1b50135d9a24791f96399f5c3991cd164' +source_hash = '224157d4b853f65ebb5f9d9567253ef0b43e940b5f3265ed127f3ca04d68490b' model_hash = '494c858c1a3082e73ca9efefa8188ae4f43abafc2d3efccf9bc7bea48f289c38' [crates.aws-sdk-kinesisanalyticsv2] category = 'AwsSdk' version = '0.35.0' -source_hash = '6f42e701f75ab00c35d2e50ca524c50c886eb950e872f4d91b6cd50137e240eb' +source_hash = 'bab7c3e5090448bad90f49ae94c162bb97d8f1cfe8625fe739027a3f512cd5c1' model_hash = '3d1480832a515174e1180e1f7c6a270f72bce093b3327d77bb980ba8cfa34813' [crates.aws-sdk-kinesisvideo] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a338241a20283289af8f2e740b221d40c37cfb36e4c0a673b416d4a09b1c0972' +source_hash = 'af7473aa4be6f2da808703e4991c323aeee3a2552a7bfb67cf0f78f1b9024a55' model_hash = '1b935d14ec447f9b41fc8e810495047ff13a02fabc18eb67eade9518d747168a' [crates.aws-sdk-kinesisvideoarchivedmedia] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f7acb9c356b06eb936ab02b6f79b165caf8d28e09236493ffb4a0f942d20b882' +source_hash = 'bcc34d6680c78c791f74ec22825669663b9d4b3bc5b62ac7ba9f6f53dc7604b4' model_hash = '757817ed7459e6d157447535fd55b16592e174d22b554cfdc5620ad3f78b9ca2' [crates.aws-sdk-kinesisvideomedia] category = 'AwsSdk' version = '0.35.0' -source_hash = '761737b9c8914853cb749378ebce9d354d4e3076d1d7be10a575cfbc67e3875f' +source_hash = '24cce0b081af62d659586d9f338077be6291300ddceb340a17e0a20250ce8131' model_hash = '671f36d68e0e0b0c15bc9fd98f50cdcf5578d20da693d49d6d590279ec6fee36' [crates.aws-sdk-kinesisvideosignaling] category = 'AwsSdk' version = '0.35.0' -source_hash = 'cff54c636896eef7493ce8ba1b8d1ca5d25012b2d159fb9e6af5074cfc445c29' +source_hash = 'b5642a39a26aa34dd533acbcdf9049ac93a564495020dba4ea9c7fffb30a9f3e' model_hash = '7c4b92ed6a5934c6461b55720aeb89ee62a506f030532e26cb2ddf8d84b37aff' [crates.aws-sdk-kinesisvideowebrtcstorage] category = 'AwsSdk' version = '0.13.0' -source_hash = '6e18824bd54dd85527b9f3703391ed1542c246bad2c92f04d5da03101353bd70' +source_hash = 'fbba887b437800fe5c227a82b750205aafe91df5d3aa1481f4d2c508f0bf4c1e' model_hash = 'e0280cb2e8d6dc367391712cb856c061a0c6189fe3dd84bb23ed3bd1c090dac0' [crates.aws-sdk-kms] category = 'AwsSdk' version = '0.35.0' -source_hash = '8d1cfa2753c0d6b0abea443d599bd5ddf3e25b0ae589313c438d09251cd1f411' +source_hash = '7a4a394381487a31a264ee0924ad6e126b002b283432a837ffe4e1e69336ba6e' model_hash = '00f8ee3d11efbab2ffb1cc0f03a667041b8b4f91fa815fd9d0a0dbc69ffcb27e' [crates.aws-sdk-lakeformation] category = 'AwsSdk' version = '0.35.0' -source_hash = '6cdb5589f55418b8a0bceb48b3ef2abcb56c895100c3b6aa4708bb816bf1d7f8' +source_hash = 'acd73af66ca65b19b584c1d0d06add0761b89d8e5bfe62f327bf85b0c9695380' model_hash = 'dfb729eac3e7748acefc78117b52bd90d98076ebccf534a0f907b9874dcdef19' [crates.aws-sdk-lambda] category = 'AwsSdk' version = '0.35.0' -source_hash = '3f36c804d1ba84d4a1fa69bda595ddc0a97bf8972caa262eb835b3effe092dea' +source_hash = '86f2987dc042d29482f1b55ab2f0814690f78a811f29b010cf442533fd362f3a' model_hash = '2229f7a79cb22fba5ed3804006b203a1288bd580bef64327c068e3908a14abcf' [crates.aws-sdk-lexmodelbuilding] category = 'AwsSdk' version = '0.35.0' -source_hash = 'efc657fa19b95dd8a111e3e34e0bd2724fb11a978bc5c185ac56d5be5060e2e1' +source_hash = '4b15abb2a4e4193c558ce0fd29d31ea42daaa6a08882683c49c9e5ec09edd776' model_hash = '35c3a19d228343d030ddd9373b5bed448dc3d27fd807c3f716c95e6f30bffaec' [crates.aws-sdk-lexmodelsv2] category = 'AwsSdk' version = '0.35.0' -source_hash = '4e67d1c7d4fed0ab9c9d2aec3eb5a921ba2e80e17cc1031b4915794c59ff4a6a' +source_hash = 'ed1bf3ce5644689fdfe46fcd7166cc931c2f528cf4bf96c7dc4aa0c4ba6c4a03' model_hash = '62c290125c4a09e6c6ab25afebda9aec77cbc12e7dbf64e823f550e8e24778a9' [crates.aws-sdk-lexruntime] category = 'AwsSdk' version = '0.35.0' -source_hash = '64bb0dc379c23cf72a29edeaaccc4621a5d20fa34d2eae21e1e620b4af784b32' +source_hash = 'dad10c4327446176d8c270ec12a7a688f79f14261f8b9991497eddc25dd06e15' model_hash = '596a20ac4ea87fa620ce112c5335a475c8dce6ebd097c824fc284a59d8d9e664' [crates.aws-sdk-lexruntimev2] category = 'AwsSdk' version = '0.35.0' -source_hash = '5e4be351829fe4be4f8e29e23bd10ea3a0589b7b4fc3bd3ac2a0c93c12e46c6a' +source_hash = '2bb9139c481bab569280747c6b4b9aeceebd4d09710a22d5de58eee191fc64d3' model_hash = '7004585510ec126f758411110edc693acffd88abb8273379e2acb75341dcdd5b' [crates.aws-sdk-licensemanager] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e31692df5007af5a285533e1b1e157ade28fdfd787eb8059845a6264f3c962f5' +source_hash = '4dd426ffbe5415cd7c6690f03258e318a12fe09264f1204ea4bb4f628e1cfad9' model_hash = '24fbeae2a2d682fff95e6a5b8ffaea36d02db2d983a60a420d8172596e15b2c4' [crates.aws-sdk-licensemanagerlinuxsubscriptions] category = 'AwsSdk' version = '0.13.0' -source_hash = '6d072048bd052631dc8b89b337293138908a8ab60b308e392e02383045a1a361' +source_hash = 'f20364f35f18237183dcc47d6ccf5526d2891dab598054858dcd02bee54af9ef' model_hash = 'd602d069c9d51a7f277f065e84255646eadc1bfdbb344f48eba0eb7b74ca9b1a' [crates.aws-sdk-licensemanagerusersubscriptions] category = 'AwsSdk' version = '0.19.0' -source_hash = '2a39e2c337083802070f63cfb552809ac7dd2b40903f04c80cd095f1ec982957' +source_hash = '45c3ad349294733df1c983c623ddf02ff95cb231b6811fac5cd0f16ec54b80ea' model_hash = '16446970b85eea4a8a7ba6488541f28cdad132ecd2fd0de394d3db9a3ed1b89f' [crates.aws-sdk-lightsail] category = 'AwsSdk' version = '0.35.0' -source_hash = '0801ecef11c3a88624b41471c4b56544ec38f22923bf73338374d184aa9ba99c' +source_hash = 'c91c798b3760aec936df9eaea22390b2809686a96053074f38f101efbee9b71e' model_hash = '51dea88d120b383d758e4234f219020fbffa40d1e23f4e2b69f8c3fd1efc7382' [crates.aws-sdk-location] category = 'AwsSdk' version = '0.35.0' -source_hash = 'b802d1c0725d9185d8e1a0d26a7fdd541392d1167be7d13630e2d161ce77544a' +source_hash = 'e679ac40db3e0a3eda5a427f235b90cd0258596b6491c31c58c5c7ad1ccbbda6' model_hash = '0b910ecacc3f05f7c9f1ecafbcf1354de60677b0a5f08b32ffe8f5da033e40c9' [crates.aws-sdk-lookoutequipment] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ab469002c27c8518098c5063041efaa60935a42b501fdc6e1d208e633c73ef53' +source_hash = '3f0ae9dbc4b269a21bb86bc91b11497e961361da925fbca7a264c603d49917ae' model_hash = 'a2104352d253154c72c1e83a6556e84c1e886fb336fe9c039bfc140a42f492fc' [crates.aws-sdk-lookoutmetrics] category = 'AwsSdk' version = '0.35.0' -source_hash = '3c5985d1300398ca6fda95c5f3c93dac0129d2ef5fcb6736c996beaf5b5a75f6' +source_hash = '1209b5f25aadb7c3a9285aeeae9de2fd624cf6e7ffcb1045c985ee2c817db668' model_hash = '6049c3732af55ae19aaca27dd9e669f7d3b99e3c1fddc43a3a4f1541a933e83a' [crates.aws-sdk-lookoutvision] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e5e68558396f8c851486f89ea3dad48b29d72b40fbd55b7c37d7a2c7597c3a45' +source_hash = '66f3ce921a062b6be14e512bce76723bc1ff26376277309547f544782ac280b1' model_hash = 'ad9b57505093a165cbe3fe1e84c3252c99cca170ba2de812a5c5ddad055219d4' [crates.aws-sdk-m2] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f911c94573ed3cb62d39c7acae1c7f279590e0c8eeb02706ddfbcdec6a6da609' +source_hash = '4602cca7ef057c9ec4889214432e4fa2888fa90e13cd348f9bfb0e6ea3292e87' model_hash = '36682e2bb0d68013b2c26d7e4b6ccab40b380e10394c545c3bffeeb62669a5b6' [crates.aws-sdk-machinelearning] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f16f38f632aff899cd63154c6e39b1edc19a1223b2345ac2e243b6439c11eae3' +source_hash = 'eaa000be953f4871bec5922dfc936997ffd71800ad57f605ea9bd0dc2a596bb1' model_hash = 'd4699b73b87a37092a5c012f626266886aea7e13302c6279f82c4c81f7106744' [crates.aws-sdk-macie] category = 'AwsSdk' version = '0.35.0' -source_hash = '6490381359e00ed2f7b09bad64042fc4b385a0f3a8976e6dc13a3cbd3e63f69e' +source_hash = 'a3ae90619981793a042838fb9c346fce5e40066a12bd3955f93953afa2314dc0' model_hash = '4bf61c3696e744077a003c129c7e366a68f40f1cbff8307655821e07bc956c7f' [crates.aws-sdk-macie2] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f43b73f15ee1b68dcdb37e9f54c65ce3d3e5b1da6d4734811da1ab70506c3933' +source_hash = 'e1623f9ec818b4362f600ca0115da23c8672f62be75bc2e3acd8b5b79e06be33' model_hash = '6b1888c2507f45106ab3effb2c6a6e43a9752ae28cb923d9c86d9d13f469d0d6' [crates.aws-sdk-managedblockchain] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e29906fa567fa002c0e7a850562ea585a83616f9689256f9b06eee387c05c0ec' +source_hash = 'ef0c83e5a035ef82a9d7d80acab35fed11f8d02ae25ae56687b1a0bba1760829' model_hash = 'eeb1a56d8e4491f48e73176b9506c36d413c726f5294ec2bb639b82805742934' [crates.aws-sdk-managedblockchainquery] category = 'AwsSdk' version = '0.7.0' -source_hash = '2c049609b3e34e8d11e9dc61aee1a2c70740f280fff03b965176515ff90f0aa5' +source_hash = '403ec14a39be0ca2de2fdfbfe0894078c6c8a552a7dd3869b858676430fb88fe' model_hash = '62e348240fb4135ad6907a3454c12d87d630858088b821d17df28b7ce3c08976' [crates.aws-sdk-marketplacecatalog] category = 'AwsSdk' version = '0.35.0' -source_hash = '6676f847c695a8861a66be4a5ae54b95f48eb701382208250d9eeb01df688917' +source_hash = '8fe5ba8c3fee10bf2fb2b4a3c270ca448ece4d0f140bb4721faa0806e3af1c49' model_hash = 'dbfbf3ef15206aafdd3582d5ed52cbe24726f4a54bf6e59f911180ed2d2f6848' [crates.aws-sdk-marketplacecommerceanalytics] category = 'AwsSdk' version = '0.35.0' -source_hash = '7e39e641e0da4fdf8a771b4a0153d941fc13df6767112232ce2c322b7f08b91e' +source_hash = '3bb2409ac3e8f84d97c00870f4b675f4db6e22b7958c85731d9f5d3946115f71' model_hash = '169990f7ee1b7e3faefaccacaf3063153e33541d0d5522567d9902b3332fd29e' [crates.aws-sdk-marketplaceentitlement] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e7dc4f0eb44ac7d4dc73f8abe3650d91788707ecb3dc0a35d96d12e8abc7cd6b' +source_hash = 'eb69824d6eb3f1a2bb909a1f4e6be4b3e2e62d41de9ffa4abc8ee7af8dbe8705' model_hash = 'd23f63af18d09b31a07fd01180e61c9ede4ac07f96d5e87098994a4e1502462a' [crates.aws-sdk-marketplacemetering] category = 'AwsSdk' version = '0.35.0' -source_hash = '7227e16b0d1819c1794fd62cb04279d170a8019f21530c0ff4265134a93536ec' +source_hash = '8f16595af45f4ee094510f94cb9b28a96b7fb4a805b3eeeadb2c4115ad3afc95' model_hash = 'fe75e39451e44295d1ad9f365568e20f949776b676536aec5d13f5f5db0663d4' [crates.aws-sdk-mediaconnect] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a967c3871c1638d7e4db6962e0b851b2c940f2294203807d0c582b68e56f357c' +source_hash = 'c1e2013e3f7b95cd26c2bc1a626fd4eec6181278bc42a9bf1cc46641c04c9a59' model_hash = 'd5279cdc9f09b006c77d9b2a0af652cdd4e5572284144b2db819e33e44ee0849' [crates.aws-sdk-mediaconvert] category = 'AwsSdk' version = '0.35.0' -source_hash = '75d85bdba4927afabf4b11b16df51452d45e934f1d9f18d65ec0acd9b78023f4' +source_hash = 'd79a3828fe1f57726aa1121d55fc68072aea78592dc461b59723ca18d2273ed1' model_hash = '53d28f1324e91e26c91ac0a46bf015baacbe7bcbee75c1d8071c899dbc63e9c7' [crates.aws-sdk-medialive] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ec8cf7280f63c9ea1acf20bbc20bbc748e6db3ab74e3349d8559bdb45e8ab317' +source_hash = '997e036021034ad48b8fd799ddb0d7efeb0812b59c7249ca31015799c6d87162' model_hash = 'd8110d2ab25a13a1f7e3785a0bc31ffc76dd62cecee03b1ffb9685769495bdc0' [crates.aws-sdk-mediapackage] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd7b344af8b38b0819ccaadb54e0e94393bb1d8aff9fa98cfd2eaed5d8bc9bc8b' +source_hash = 'eecdf8594d651fad2a0d5021829ef96519363eef33e79737ae7f2580fe735229' model_hash = 'eba92252b08d81876cb34216c564596c01cb866b97cb72525922f6204700ea6a' [crates.aws-sdk-mediapackagev2] category = 'AwsSdk' version = '0.7.0' -source_hash = '07b215a0e9c6e1b30f313355ccc22ae107ccb78bd14e566d89d7886569ecc220' +source_hash = '0df3f36ce9ba18efa5f5c6b594dae622fd61eca1e105efe04d06282256a33cef' model_hash = 'b32272b05d6399def606b48da03cf2bbcbd57a343805cde5343effb056f89600' [crates.aws-sdk-mediapackagevod] category = 'AwsSdk' version = '0.35.0' -source_hash = '416f31be866ce1acc20b09a888d39e93a4abae9a8ef7f40505af722d277b2e4a' +source_hash = '678bd5fc7fc881a977be5f9b22a67ee87c2a58fc1dcd28cdd6af6007b858569d' model_hash = '26ac5422bc7566d50c746c8990a9fdd77ae3aa6a4a1da500d251222be4d9b731' [crates.aws-sdk-mediastore] category = 'AwsSdk' version = '0.35.0' -source_hash = 'b7b3dbf9a2dc6c61dfec0f5505832df099b21bcd45e740c63a3f7ad2d995da11' +source_hash = '55d4b4bcf235b21bf67d0f8a62c63591d90a8b51b6ffa0d1c0a0555e992485c0' model_hash = '4c2a839b494422238ecfe7aed4b9ef4af99728044a9c9c74d3f67dd30698b16a' [crates.aws-sdk-mediastoredata] category = 'AwsSdk' version = '0.35.0' -source_hash = '9c51ff5e1cc8b28c1996a5ae443aa5eab91cad54880f1fc44cb2d334dc7f4e07' +source_hash = '4f02a4351682b2cae55c360cecabdeecb98bc99415cf5395ed2ca85a650d9771' model_hash = '5f37ca20e94fbb48d218b6a952a3b36c008b645c17f4eb2aee562342137b4d51' [crates.aws-sdk-mediatailor] category = 'AwsSdk' version = '0.35.0' -source_hash = '6d6a7e28e890ecf678a63af93c6b22f882e76aec853142f9272aac58de5d5716' +source_hash = '65c598bf18166247b5279f5cc949fe0b5f658aa66cf76a31cc1a6063580e34dd' model_hash = '8f0cd50207cb7581e4e96b7b5ab1e24e4a482b4a597e0bd27a47afdef0673efe' [crates.aws-sdk-medicalimaging] category = 'AwsSdk' version = '0.5.0' -source_hash = '33d3aa995e98612c7477611d2941f48e2f8cc9992c38fe6e758062bcb8752497' +source_hash = '41cff278ca2ca944756d0abb5d6d8e33b9be4133f0f4fed4c79fe979419c06e8' model_hash = 'c1d9f4e1c3feeb7322bc562407ed15c321800702311a03394eea90f1d77d6596' [crates.aws-sdk-memorydb] category = 'AwsSdk' version = '0.35.0' -source_hash = '5e071adf1a58e32663e30a213c9687ae3142a60761faabe62473918c0b473378' +source_hash = '16721c80e36caa09ce8074162fad8eb6e06b47ac739ccf254011c870955d00ed' model_hash = '66ee16cbac6d2728aa9ce4e336338114c6f6924bb280ebd47eb649b5efb5909a' [crates.aws-sdk-mgn] category = 'AwsSdk' version = '0.35.0' -source_hash = '474187883fb06baa50b72f7503c9fd657c0747b1f353ca8a3606130b94ae153b' +source_hash = 'a1981f67939af972ed1837f69cfc8a0b15e6a3c79903c76bc9901631414da554' model_hash = 'd5f890f87a330194307b1a2f3587e4dcf366248c5fd3ff4cbee24f36a1ec71d9' [crates.aws-sdk-migrationhub] category = 'AwsSdk' version = '0.35.0' -source_hash = '86f99ff63655fe60bacc04d36097b9d2a3a4eed74e917e1bd5bde3a3637c013d' +source_hash = '2593131f46140ddd09230efcae391e8167d3c8b0e3fa1be5ec637949799e7098' model_hash = '7e0bddfc3eade68674fdf4c34f28de74c330606c83b9ff807f53597f15ba80da' [crates.aws-sdk-migrationhubconfig] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd10ae23b087b535c016be0b5247d5591702338f0974dc8cce9f5736e89d60956' +source_hash = '889641079b95dfd7e90af0069f744b22942b87456d8ab7ca1284696bbc42103e' model_hash = '703bdad748102aaa909f7ca665e0bdfe9b9f56a12bbf0c355241a129a0352223' [crates.aws-sdk-migrationhuborchestrator] category = 'AwsSdk' version = '0.16.0' -source_hash = '48d39839301e14d2f20c5cb06ea63b32c475c650239b535089cb12a6f6dc9596' +source_hash = 'f68d24f2b8eca2fa6e5a7582192f030983448bf318fa5878be72f854d80acc04' model_hash = 'e19154923da5c87ba17ef4b2d44b3ccf93950fb50889b1b589901bf7fbef4c49' [crates.aws-sdk-migrationhubrefactorspaces] category = 'AwsSdk' version = '0.35.0' -source_hash = '8ee5b0d22d766eea49a18bae2faf60bab117601639cf0ff6d8c22ba6be886400' +source_hash = '05632d529c939c58056abe9bc5eb3b0cfe203d5b7063d9984094a5bee3d3fb68' model_hash = '7ac3f9a38041a038768928b8100787a2e8fb8909f742c501a68e561f8ae5489c' [crates.aws-sdk-migrationhubstrategy] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd00dd4aebb8d817c0e1855c7d21a17052790a76e02b9ced72cdc21b9fbb8e298' +source_hash = '86d1e9f06e1b3024842527472fa613ae7e386dc26a1592c723e64a8502e1f96a' model_hash = '0b2b9ed320222b207b03eea464800c2ec5d7fb929a6348978e837e88144ed886' [crates.aws-sdk-mobile] category = 'AwsSdk' version = '0.35.0' -source_hash = '52251b2988f84039ba354924e937137c054eb77e1cc8813aea1ba2ae1bb2859b' +source_hash = '436bd92febfd84534f05472861035fd16f491d33731263c82cdbdb5bc91fca9a' model_hash = '92e9a89c4b2d472d264a408d95553fa2610639a5fee8dd87d65e88806630dc15' [crates.aws-sdk-mq] category = 'AwsSdk' version = '0.35.0' -source_hash = '23c6bd7a79443e0c6854b4707deee9c16cce57cfbd59b6ab9aab98e0a2b6e997' +source_hash = '6c4b421e289a5ffdf61320fece72d0b65effd17749c7be342c662d5c9fd812cc' model_hash = '8d6476717751b50770784f58a5bab647d5b9a1774a024cff977bbcbaafe691e8' [crates.aws-sdk-mturk] category = 'AwsSdk' version = '0.35.0' -source_hash = '9bc12d5fc5e6e6b290e554c03ec885141c150080fc2cfa337cbecbeda7e20b0b' +source_hash = '79ec0c3c33def63b967c27cb5d11cce52af4e84355cc46548c0bc61d12a8bbba' model_hash = '1cd1e08bdab2e0bd55d6d6ea1e5d4e7ca54f6855513da0051007316cb9e923db' [crates.aws-sdk-mwaa] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e793b18d01fc595a5a17da8c5363a36b8f854a89348e18407145c5feee741e5c' +source_hash = '612103323042faa050f935565e0df555387e80eaa44685e6ca393ec18ff3df45' model_hash = 'a6a0df1761b5ee8d8a1d376fac6c66d13a89cf6e55cb445f85c9e1d83bccf65f' [crates.aws-sdk-neptune] category = 'AwsSdk' version = '0.35.0' -source_hash = '9febf127c723d788c5c307fd12e97e2119f3f1521822bec1dadf10d575b8ab82' +source_hash = 'd7331ec5e718623af3f9194b78086b4836ca6abe9fe2c96eae8e7d70b564a794' model_hash = 'fa50925874545dc540c8f5002b3609b0b67eed426263d0d7644f08713affb710' [crates.aws-sdk-neptunedata] category = 'AwsSdk' version = '0.5.0' -source_hash = 'df161ebd22d62adbbe471e212b1f178f52c779c5fe97416c284d81ea13bbf5c3' +source_hash = '362492794e43cacecd44425deceb742192af2509480be0024ca338a529e4325c' model_hash = 'f59a0cc9e179f82956a6371f9019bd76c16766bc73e63948cf5e27559700200e' [crates.aws-sdk-networkfirewall] category = 'AwsSdk' version = '0.35.0' -source_hash = '0020ebcd73fab0e111cfcddc55809eaecde23e10d0b5a3d72cde0d068e288a8d' +source_hash = '7cf61fd3b1058cc443c1a7fa7ac0661f6b8bc1cb4dc0cb8e07248b40992e4cf3' model_hash = '8e07e2c29f747dadce30c991977c3d2f1174b9dfdae3db64d28ec7f8b17c7554' [crates.aws-sdk-networkmanager] category = 'AwsSdk' version = '0.35.0' -source_hash = '0bfeb820cc75b91e4a9de2d6285dd97140918d04eebe554c1f0e65c12c013df4' +source_hash = '78886dac0975efbd9c9a43e91c9f6feeb278149a31b7ad41303a7fb4cb65b461' model_hash = '8d93804db37dbbc782a28e21b2b5a5b25131db06333040999ae4fd4af277e50f' [crates.aws-sdk-nimble] category = 'AwsSdk' version = '0.35.0' -source_hash = '733b2ae75268ba8a94907d37e340fff0d8f3045263f38ad6c6e1f8a942f56a37' +source_hash = '6df655971df058b898319f8743cd064e17f1fc8ef0587bcff6239549debe92ff' model_hash = '85dec651b166eebea43bfaf1b96db842ad1c930667f6959601501b29b37072b4' [crates.aws-sdk-oam] category = 'AwsSdk' version = '0.13.0' -source_hash = '94e67f5dcda400226caa94c2fcc5c387be45c2e5ef1ad8a25e0c8444a14820e9' +source_hash = 'a5fcaca63fe1269e261087c3cc0cf2221f5e9413ece7c1e3b24d01cbecccacb6' model_hash = '3a9f2a2b025e26890c09b90da386dcf55d74b5a512ed333c23a45bbe415c1350' [crates.aws-sdk-omics] category = 'AwsSdk' version = '0.13.0' -source_hash = '0162e00217da8086db6da1f5502766fdd4fafcf07524fad2db94f41bac585de2' +source_hash = '8ce0bdd421d028657bd35866c64ce78bc3842457b2b7c761312eb6f8647d53dd' model_hash = '169acebecbf810756afe80419de7bd5c1d498c9ed2d05ee20888da54eea41e68' [crates.aws-sdk-opensearch] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ddadd3ac543b772c5f375ed6bbe4b6b4423594d04e7187b312fe5ccfa809f466' +source_hash = 'd3f6a5140ba09441a1476ac9c370530c11cd9749dacd0eb96548eac5ad401de5' model_hash = '803a7112d8e699e17723b87d3e8b5e5b84ae8623fe368fe9b15cd1e607e7c0c8' [crates.aws-sdk-opensearchserverless] category = 'AwsSdk' version = '0.13.0' -source_hash = 'c0da9b137f9acce93d4855f9a7a49b699c363e89916023d6333443297cc8996b' +source_hash = '2114fdee483b0788f527560d251ddcc7379a7407989d941a51971eb1650f7064' model_hash = '72056e449f2d07d8e90d3d14556a79c392c4fc4c37c7f1800bfa0acdbff82212' [crates.aws-sdk-opsworks] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ee8a1b936a751874e5091e6c1e4fee379cc3b40f6813e18287dd551ecabf5002' +source_hash = '2d1652b657e6b5b7fb0400342752afaf2f7be8754018fa87c0f7b4e4691fdcae' model_hash = 'bdc48d7454d51410766d13fd54b469d6c613128dfa83b389bfad20913a9805b2' [crates.aws-sdk-opsworkscm] category = 'AwsSdk' version = '0.35.0' -source_hash = '463a77e3c7014aa993b93667ff06cea982713adbb0ef2257a053c2df3b9765c2' +source_hash = '5bc2af9c9d003d08081da7ae755e2dec1198ed4fb327272e335d12b449a4c6f4' model_hash = '94fae3de41f095f1626b2624ea61356b9e50a130845f08ed021b777cd63a0063' [crates.aws-sdk-organizations] category = 'AwsSdk' version = '0.35.0' -source_hash = '1f47eb724f38840fb53dafbea111076590f8bf403df162c14d036fe3f0f14d82' +source_hash = '872b409326a7af29fbe38b682932b13a0b06a66f41de1fbd679627bc2fb63606' model_hash = '92c7b6c1103589fb1ab8989d4b62f1ca23d8e499a0c9e4d8e99defeb847b7645' [crates.aws-sdk-osis] category = 'AwsSdk' version = '0.8.0' -source_hash = 'b2aa5c5b22fdc8a881cfca3bbf3e0bd78331867c826c3eafebd5a6168d7bd179' +source_hash = '1d41fa20ca0351aa47e8f7cdc65dc7ab5fd816bb8456ceacbc3be4737eb56446' model_hash = '1c66bf0d4216d6aba2b1893e184090ab3c351dd9cc478043f16adfa7c68652fe' [crates.aws-sdk-outposts] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f71d03ad3533fc2729f01b08ac69daf1d2e01bed0968d1a63f7f3496932fc2a7' +source_hash = '4bd7cc5d01ed3c971882b8a2c9c308e7c6cd80c31d704337e01477dff3949f25' model_hash = '2c38221952a0eb44a5216888abb8d2492348690596876278659481fd4ffc3454' [crates.aws-sdk-panorama] category = 'AwsSdk' version = '0.35.0' -source_hash = '10f40c8fa2513df580b4ed7a257b30a5aad56333d401f50e8ab9fe8d17da7014' +source_hash = '1d84bf28205e911cc9864a683f3784ed2f83ef507bcffd5aefaccb39bb26cd2e' model_hash = 'febaa3d19e9d98c7c7888395b77777d20b9914187a054b1443a86e9a0a5ab35f' [crates.aws-sdk-paymentcryptography] category = 'AwsSdk' version = '0.7.0' -source_hash = '236615aa845fae59405084c404e585837b60c87eb06e292f5cbf7a38a0ab935d' +source_hash = '58722b64631e52c82a7d91c36fe73aa7c4984f1cfd036866155cd6c09e150e5c' model_hash = '6b872e3a3da4515df530bab846886572019c0c0461d7ff675f1a4b36d5085871' [crates.aws-sdk-paymentcryptographydata] category = 'AwsSdk' version = '0.7.0' -source_hash = '7be388f52c4d9aa10b25a399c17725fe0ac1d598ca669282128094d30cdd5155' +source_hash = 'd6e4d9618b9bbd1cfec300f56ba7df7864d0ea2a988c1bd86dbc379023c14fa2' model_hash = '911123771bee7b7343e09cd2726f547a2a56290b0385ba61e2566f827bae3152' [crates.aws-sdk-pcaconnectorad] category = 'AwsSdk' version = '0.5.0' -source_hash = '30c832bd5a328ae7f37155811d435e1b869eaddd5142a6c87000e8367851f03f' +source_hash = '7dcce903a3c3ad1c3d871db92dbebdf0587c17d89f354a386fb9cb803ab3db38' model_hash = 'dcd33f1b50d80dc3d4502f1f156b4d6d74444f011da309c399ea95b0e99f6e47' [crates.aws-sdk-personalize] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a8d00e1952fdb338494eefd78ae5655bc6f383847989c3c56f92b613045611e5' +source_hash = 'b1f0adee3940eed12f922564426b9c0e867789682799c8bba027edc3e491c3c3' model_hash = '6331ac7eb108e2a68addd50c67f77f093ed8e5ea831f9fdf98aade5d971448ee' [crates.aws-sdk-personalizeevents] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ec9921b792eec6ebba5ae4c4f0b912a6acced567b31e38149cf043bb16dc9576' +source_hash = 'd9e1619c8a0d3c65ba11b47c0e2f45dda08db14c6997f7675955f847e1c47fd5' model_hash = '4586c1c44ebecbcb75a45a1cef4aef4876d3b31855002eb33a34101c0359e140' [crates.aws-sdk-personalizeruntime] category = 'AwsSdk' version = '0.35.0' -source_hash = 'bfec2ea5cc5320556b143814df22fa220157deacbbad3bb5dae10d88a5f8b4bd' +source_hash = '7e61f3196468961fcc8661872f9d7a74d6d7b6b54967d9a5ea3156e186bb28cd' model_hash = 'd8b6401b730c9743349e6e51cbff4ba28a9d03f8480d73d660256140f3987661' [crates.aws-sdk-pi] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a9cfd7b67bb19311a364134f4ef01d51a3f5dddc1fd03f4623e1bdfaae1870a9' +source_hash = 'd7eb30fa63406c2f6ca2553ca51828664e97408a30067ad617fd2eec55683a90' model_hash = 'f5f79e4e53bb45d6ea1f8eecdf31450aa0c631df87b7ee2e699630f709d36c44' [crates.aws-sdk-pinpoint] category = 'AwsSdk' version = '0.35.0' -source_hash = '99ef2cb0f62f5658c8382d1b3146efe1306975258425a27f8ca2dcdd74f3eb1a' +source_hash = '404028e45569fa9d91a2066ee3a56d4cc123aa364be7622560416e6e545c8d5a' model_hash = '6d9418242fde10c4d55966370b4316b40bbdb5ef94da74144f8efe2833bf010f' [crates.aws-sdk-pinpointemail] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a9c1a57ca4888d644343c3e3fbcb81053b8b5b6179fb32664ddfb54fa15d16cc' +source_hash = '8c008059e3eb3de4b8de9f4fdc5efe843776c017b99ae57e1243bb9c3e5bf304' model_hash = '2e3995f2bf969329f1afec93f33bce0cd529a890b5f86d84ee5f538d138e5b56' [crates.aws-sdk-pinpointsmsvoice] category = 'AwsSdk' version = '0.35.0' -source_hash = 'cd8dcacbebb2e96d3d892fba13aef8a4a862d325990b4344ff04fa67abb43da1' +source_hash = '71549e6ab3d289969346314ed61e4bfb89ef54de01c47625e666b491320f69a9' model_hash = '1c88a67d16451b4c40c3e7f51f3020b6961f62187c4503fc4788187849855a80' [crates.aws-sdk-pinpointsmsvoicev2] category = 'AwsSdk' version = '0.35.0' -source_hash = '11a26f0f6a4a9c272727fe66db85ff4afd27a1ae816b08f46dce9d36a265539b' +source_hash = '6aefc5aab01c46580e8d73f8813ec1ae14f3ffc9c7109a0b8cf50df84bdce6a0' model_hash = 'baaf8452171e65ff47584c0fc2adf66c93e9b4c05df3d271bd0ab8861abb88d1' [crates.aws-sdk-pipes] category = 'AwsSdk' version = '0.13.0' -source_hash = '28956648f6b0155b91a9006eeeed2324b466f77483badb4c279ee146a9fe2cbe' +source_hash = '8da48f20c3845d1170c8c0538ef0104c8632a705f6e757d482b5ddd5b3d1090c' model_hash = '544afb8bd8257f765fc99d2bfac728b6258f6d47b155de085f3f5f50d57cd40e' [crates.aws-sdk-polly] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a001b4a19e53c6bf5f383fe2e5cd45d129227ccf0cdcf013b5e7ae28d3df9edb' +source_hash = '4fbc7401ab4e09b3454bc84031257feaa36572e82d2fdb384530c8551d24d8e8' model_hash = '913ed56b7bed377c1b587b9b31cfb2103650ebe93718bfe65f0bd6e1ac8bfdfb' [crates.aws-sdk-pricing] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a1134f7d67100fdae0be4b40a428845ceea73ec725fffff934f50414d482c709' +source_hash = '3b5ef92661f07145c3d9758c554f7433753c6484eb2c1ff5cf93d84946295bac' model_hash = '78728f0224ed1ded8cc8e4fabb56ec07935dcbc3b1d562b237c9a3c6607779a0' [crates.aws-sdk-privatenetworks] category = 'AwsSdk' version = '0.18.0' -source_hash = 'a0e750dbb8e96035016dd02dfa46f3ca095b2c110aaeeffcb4a989ece6c96689' +source_hash = '38dea03d1f0d6cbcbe3e82d98e4ca768c0d42bef44c631458f2b4a2eb31b90de' model_hash = 'c9861594f0c5119053f730a377bec52cb857608804185ab3a19d5a5027765a69' [crates.aws-sdk-proton] category = 'AwsSdk' version = '0.35.0' -source_hash = 'a7eb34d5f9bd9b3dcc77cc34355e8bed1ec42ea2032725500b99c7ed3191c85e' +source_hash = 'e98650f251874d8ff766fecc10af6dda9e7df6f6eaa76ddd845ab80cc702ffc1' model_hash = '70d8c095cad5fe369c404229900eba9fbc267d4db2cfd7fb925fe0bc65181dcb' [crates.aws-sdk-qldb] category = 'AwsSdk' version = '0.35.0' -source_hash = 'bf0bf614cf79eff30a1fa3615c6e19e1b2ce606a280a590a508e2ecd680cdbe8' +source_hash = 'a5d5a370603bc251f47f53cc18fbf62d1556950ecee49bd758a434c2433bf80e' model_hash = '566f48b8784a7b21b58c93e06d59903ba31174c8a718babc8b4f38e9be3786ad' [crates.aws-sdk-qldbsession] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ea800f93feac110c61f90a704b233f808d70c0bd9daf1f93a384ceeea274244b' +source_hash = '55eb94bbf1b0394f5e51896ea2e7386ffb9360383184af7783a3ac6216f891a6' model_hash = '27c9e9e5a0761cc6e79648630e51a0d6faf2ea5dea8826c722bcc5005fa36786' [crates.aws-sdk-quicksight] category = 'AwsSdk' version = '0.35.0' -source_hash = 'eb0b89ce97db281775ca2c915ac660a1706394e3c5a730e3d2423328c53f7b9b' +source_hash = '90e7aa9feaa7a10e764b4f671c1a26ce4017d5c6154dc03623a7b56a421c94a2' model_hash = '6c453a11a093360cc60a369c4d28e273f22dd4f7d539b33d7dd447be3851cddc' [crates.aws-sdk-ram] category = 'AwsSdk' version = '0.35.0' -source_hash = 'b05afe0c00dbca70f0c1a8f7b8de0f6cc14b62a8e62d66eb1b7b0ab79e6617da' +source_hash = 'af9fd1580e695ca9c0dbdb62030ac536355b2243128442c9b237897ddbb2348c' model_hash = '089a8b12162eb3a3ad06adcef9c96f68661e8a54206da0150dd56557476513ef' [crates.aws-sdk-rbin] category = 'AwsSdk' version = '0.35.0' -source_hash = '51d2d928f3ecc24885ca95887d49d4568f12942fa5e7c6aff5b603b7aa344550' +source_hash = '92b36fbbcb650b08b0d4022240fbccdcec136ef35187dda173468404afe85aaa' model_hash = '8ddb6f23161a8dd9a3716bb54ea5fb3fe24b84e0e1f53e0d22cfbe9891b9ef27' [crates.aws-sdk-rds] category = 'AwsSdk' version = '0.35.0' -source_hash = '79528b4145d50ef06ce75d7883b061068f3930435fc957ec44afc443a4d6470c' +source_hash = '02f55a4e262d96535ede7be9c39d757fecc3406c48ea07530669e1ce0107f715' model_hash = 'd160c0f35d358aada3acbb0406c67a5e4d9c0350fdffc42f40437cd656f49e91' [crates.aws-sdk-rdsdata] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c98763e1b9afc3e2945cd0925a0c4a8711106f7cf6da9bf138bb282150931425' +source_hash = 'a75084e6c4d145f61e65369dbcb19d6521dddcb2076806291f33b698e976ee96' model_hash = '8e7684ad757d16e2bfed3334c76a8bd9e2c405cb85ebb7e93584969d40880e73' [crates.aws-sdk-redshift] category = 'AwsSdk' version = '0.35.0' -source_hash = '2219bb510e2becdbac04988b8a8361e298f8c8359d4ceed769cc678d7d02f94b' +source_hash = 'a8aae4bbee001f8d87e67d5d65f65ebc950303bc0a4c60ebfba5c321bbefa09f' model_hash = '139b4510bf69c55944619e376a87cb9c7f3c5a0574181648b2a22d1d76352787' [crates.aws-sdk-redshiftdata] category = 'AwsSdk' version = '0.35.0' -source_hash = '21d3a3d3806b19fee8dd7cacbe3379558bf3940c48009dd49bc8b4e9d476494e' +source_hash = 'a6f3306376a55675de9b7594b83bbdf90b823319f900782c5cafb2d06ebe30d0' model_hash = '1645d194dc34314c0275a1f38bb0fd1e3e85047cc9924258cfe663c0b12504d8' [crates.aws-sdk-redshiftserverless] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f9facb24d38e69315ca57417f61275be9af603c711f80b6e43f040415bbe1606' +source_hash = '925cda0a669f4b1e4f0e879563608a1dd5835311a87bc9fec82c50795932b153' model_hash = 'c1ec28a0442597b66f840f3bc46fbbda560d3d77a82fab0391cde1a55c6e3946' [crates.aws-sdk-rekognition] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c009ec1768e944d9bea9489eff94e56a21d3126f137cf223674ea3c8f368a49d' +source_hash = '2094e16c5d5a562265b4672309dbaf2647b1c5cf13d448692545d9bc9b3296d5' model_hash = 'a5bc81ffa14d0ad7fd3a3a1cbe7f7fa16ab35b322b932c115a4416966e896513' [crates.aws-sdk-resiliencehub] category = 'AwsSdk' version = '0.35.0' -source_hash = '7bfddcd6d442f02ead937ca92971efbf815042f991521cd2ccd0d65728f6648d' +source_hash = 'd93ab55843144350038bb7ec21a1895cc130061d90c783b692994425a63bffa8' model_hash = 'f44b249e6dc9d51cbe701eb2a7400e7885e648a778a59fb0be6a94cdd63e3fdd' [crates.aws-sdk-resourceexplorer2] category = 'AwsSdk' version = '0.13.0' -source_hash = 'a1588e68bf59e5570fe426c7062eb392016870203df77b5b67ac0831500ecc8e' +source_hash = '8dcf4834785b085ada0ba5a40be19abbac93e590508256177beaeb0c82f98709' model_hash = '1c860f7ed050689cea38a968859d15dc26c4a61be04657e51d32909708189380' [crates.aws-sdk-resourcegroups] category = 'AwsSdk' version = '0.35.0' -source_hash = 'eaef5698ed9195484aafd032d2c391e1f265b6fbbb14b24892bf11d0036991c7' +source_hash = '0c0a436f4be62a23d61c5ed7d516a0b922af806c5e66cda4e976936d7a912fb1' model_hash = '2c0b3773c0c6b9154fcbdefe5299d4b8f0738812ba8457c1d1f10ef8a423c16a' [crates.aws-sdk-resourcegroupstagging] category = 'AwsSdk' version = '0.35.0' -source_hash = '20267bfa23657c2a152c0f94059bc13b1dd87adb14bc5d9ce077a6d7fdd8eb4e' +source_hash = '63ad3b5167e82f925269f03aaebd17e46c6a3b79a858291d3dc9ccac9fe9fc65' model_hash = '773005ed64bcc3a4f67673721a30cfb108d00260fcbb83bfa2a79afc4898eb85' [crates.aws-sdk-robomaker] category = 'AwsSdk' version = '0.35.0' -source_hash = '375327f3b7be9da539d248b67581a14c9619fab453dad96427d925327c4fa45f' +source_hash = '896740cf73753d508fa8094a5db290e898c6ae69e70c85911978003d6381ef8b' model_hash = '7359c8d832a65dbb4b1fdc7692fb5179067e18cf531d92b5cc5e2c70fb1de4c6' [crates.aws-sdk-rolesanywhere] category = 'AwsSdk' version = '0.20.0' -source_hash = '2ed08ffab5d2a8c6eaa6a49d51b06a21f924af4e006a4c23def7c0d6731daea0' +source_hash = '7ff18d664adb9b2dde85dad5b5b29b5548ad7090465b86e6135e1f0dc545770d' model_hash = '09d5fd3c17a1ef45f28c12181c2ac3c4c1b9312f00d30790945846494a804730' [crates.aws-sdk-route53] category = 'AwsSdk' version = '0.35.0' -source_hash = '050b6bce85bc4f2aa3dcefa4ac8ab374087b9d9caae73c36872a5dd3ea9d3986' +source_hash = '869445758edd8c16ac6c2bbb3033b1f2f2dcfe03744f95330156839429aeb524' model_hash = '59ebe7dc8334941dccb9bc5436747b633e4d644a74151d5515a72c92d922ff21' [crates.aws-sdk-route53domains] category = 'AwsSdk' version = '0.35.0' -source_hash = '0425d5a75af8effea610a104a21a809ecb05bca10f685735621785d0d13c5018' +source_hash = '23458f2f9fa6bb144031b0c400a7d1a3ee749a09337237ca664433ac2d387b4b' model_hash = 'ce1458e71a879ffae3f59253bdf6e49cdc1160b72928e666400555e388792a5e' [crates.aws-sdk-route53recoverycluster] category = 'AwsSdk' version = '0.35.0' -source_hash = '40dff7a5882b32a84d38facab117bc136d33f3f376e9ade0f32772e8120310aa' +source_hash = 'c994b1044fa08e8ea6234c1385dc5a2bfd5183238690f4db99192024ec02d51a' model_hash = '59a6c922197a539b1e1a8aea103f29d753556151a64c5ca951273df2cb2e1dc0' [crates.aws-sdk-route53recoverycontrolconfig] category = 'AwsSdk' version = '0.35.0' -source_hash = 'db446d2d67581d1d6168e12de4085a6a8337f01f788c3840dbf224fc5ad7be6f' +source_hash = 'cc1116dcb8c53895d334e50bb8c3d5a6d628bde18f1827ebc39cc7b2d9278ff4' model_hash = 'e7a24052acc9c9375be129e14884058334a3fe0be09ca9c509f92c77f1c67388' [crates.aws-sdk-route53recoveryreadiness] category = 'AwsSdk' version = '0.35.0' -source_hash = '783e02a700e387d2d7f087481dda8035042203c23d2a7d34fec3bbfbbdd4986c' +source_hash = '1e7613ea20f374e784dc9b02718259f71ad67b02dbb2dee19f11107e835ecdbe' model_hash = '4174e800015b430563a53761759735a4db5bc924a4107ae11d034af8e9c6625d' [crates.aws-sdk-route53resolver] category = 'AwsSdk' version = '0.35.0' -source_hash = '1ebf6c7f344b59495c9207b831958d0a2cc81f6ca6f4fddb434ad1d68c849bfd' +source_hash = 'ed3e55749d110a02423b5d47bd4dee8a1c4d42d24d5851d03ed9b0eeb835ff69' model_hash = 'fb24e420d7903cecb7b565685dd37078485b4c22c64272aec8ef445f84a2ae72' [crates.aws-sdk-rum] category = 'AwsSdk' version = '0.35.0' -source_hash = 'fd2279774ba40ea521d73f03dbbd966d9fb2758f7c8911e29bbcbeb887f5475e' +source_hash = 'd72497d19b2a596d1647d4d42bcaefb9d45d4de621ffb5e6183a1ecba599d0be' model_hash = 'c62ce302df590edbecf1e8410825959bd53389d7aabe1ca4b1c014e9f8f3463f' [crates.aws-sdk-s3] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd36f5b546a60c7e4376d661f1a6e168fed2ea205ff01864c7f1febf647ab4fe7' +source_hash = '7716dfe54eb892941d0c1e3d3bbc2b5a601a2b2f6226fa3ee8068646e985f437' model_hash = '170b570a996cef2e6e71a9a3bf27da523d4673bb1ff6e38d97faa9db7eed7c9c' [crates.aws-sdk-s3control] category = 'AwsSdk' version = '0.35.0' -source_hash = '9ccf8e9b5d78a4dcfb061d4524cd7f2e218f8536da6c27337fddfeedbc09b1d3' +source_hash = '109311011f5d0041c35ff7fd8d43fa29e1de273a6d7f1074dd0fe75f542483b6' model_hash = 'bf66dcc72f786ebd8fb2bb7b931c2f05bc38b3c2aaffb1d7447ce49f555ac498' [crates.aws-sdk-s3outposts] category = 'AwsSdk' version = '0.35.0' -source_hash = '6fe645091d7c92842f15ccaf460e9e77f0b5281966c70e3ef018fece9ddf976c' +source_hash = 'ecbf4e262bb9a9e7bb23b639ba6ad6f7bc45334bae6277dce74f0dee2b3e0938' model_hash = 'f9e4b75c464276658ad02e6fb32ece96389662d9e55fe7db3a5a057bd9fb5b03' [crates.aws-sdk-sagemaker] category = 'AwsSdk' version = '0.35.0' -source_hash = '3e015e2086f53320e9948dfbd434148a89d35219c10055de287a87de01813719' +source_hash = '43eb5168248613f0ae63ac28ea80b2f00bc1696b88b05f5173b0e26a15edb842' model_hash = 'b5fb41123a1fecd63336c9b7e210968119b67e82918c79abc72b1918f9b3cc14' [crates.aws-sdk-sagemakera2iruntime] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c37ca96fc79b44a050e08b8d345418245f66fac41254ff4195342a96d7da2108' +source_hash = 'ff4e7a4169a3d091962f215d90853acee537f030aace9b4de776034a7e8a9698' model_hash = '1ea1bea294abe5fddbef9ea896f194d8ede696c31556e3da9906e7b103a58469' [crates.aws-sdk-sagemakeredge] category = 'AwsSdk' version = '0.35.0' -source_hash = '31d504342b180db51480ce031b3c0db9ed47c8a5a938ac165eb3c4fb0f2abaf8' +source_hash = 'f147ce6adf276b4cbddb1a758c3e19293b0e5de784626e9c876039e9ee7ad22d' model_hash = '656f873c16479eab5c6c210edffb7cb0584d9c3958b0ad5b07215375a8d843f4' [crates.aws-sdk-sagemakerfeaturestoreruntime] category = 'AwsSdk' version = '0.35.0' -source_hash = '83f5fb729c721b87920982c75bd1412f43a6b056fb4368d6053c10dca48ba090' +source_hash = 'e6f010bdc768cd5c06bc033ad83955c94bda9a90d1e03d0c24af110711ea5f4f' model_hash = '3217155f6ba025bbbdeb3e00e99ebbdc93cc177c8b747f5dc20b73ffe96057b3' [crates.aws-sdk-sagemakergeospatial] category = 'AwsSdk' version = '0.13.0' -source_hash = '2867d8a895677f9562b3ef89c86b2b9ff88ebfa26b85c3f5a9604a6cef392a35' +source_hash = '2047e5e3bfeca8f9758b6b10f0d4a51d8457ec3df179ff7134354185fa4b6496' model_hash = '1374a50b7b671cf6aa6d404bc228204bbf8bf663ed8781a90c31f10b1d9891bc' [crates.aws-sdk-sagemakermetrics] category = 'AwsSdk' version = '0.13.0' -source_hash = 'e9510d79a979a41643ab0293d7df06dd029c15aa33bf183da370519e01c601ba' +source_hash = '3c51487fc2898c2d602e0d28a0431a6198df857d3335e52ee74fcb17fb704ca3' model_hash = 'e03e606161d20458b3bfe1ee995e0c9ccc614458c6f4dcaaffbf778bdeab8f86' [crates.aws-sdk-sagemakerruntime] category = 'AwsSdk' version = '0.35.0' -source_hash = '33cca58bd701a643827ba9f862ba0b79c9d29c04789ec6c53a001e3c64ff3e5e' +source_hash = 'd556767d078de1d8ef1d6509d32dc5118df7a90a2e775f8ec4c80dca9abff195' model_hash = 'd75fb52406ae7d0a0cf191acaa5644df2398339391c76efc287b369293c064db' [crates.aws-sdk-savingsplans] category = 'AwsSdk' version = '0.35.0' -source_hash = '4dda4ad6b3a578cf6f5139b273fc887ce7f790e04d4e357852d20636f984b598' +source_hash = '2c64991f7d89bc686d85534dc7604cd806e393c2285cf23c6e2409fc5da6cec9' model_hash = '73740c3536780079c11f1b917c81eed2600d1ae565ce64eedbd3ecf616aa4af4' [crates.aws-sdk-scheduler] category = 'AwsSdk' version = '0.13.0' -source_hash = '1c04954325ffc0710760d3f037bcf9d2925641e1c19282c453c62df0bb73ec00' +source_hash = 'e393ff34827d30f25b366dba706b18f0e6895352b311349c018df60232b8121b' model_hash = 'a2cc9a2ba86218f1943a36c8c0a0d7fc5d6877a1b7993f3b1487412d2cf9d1ed' [crates.aws-sdk-schemas] category = 'AwsSdk' version = '0.35.0' -source_hash = 'dcc381c9912ce9b25575976290e58e005d13cd9155696165a448c27d5cf8b7e4' +source_hash = '2e8df187f92412cc4e4885b190a1fa174ea64c1873fc6c79b902072b20cefdf4' model_hash = 'f1ac740bbf221d07009cb31840d1d0cc731e30ff3d153b018b1706258e5619f2' [crates.aws-sdk-secretsmanager] category = 'AwsSdk' version = '0.35.0' -source_hash = '4e69243fdbbbd893102553f63d09573c3345c999d1ea7928aa36bf25956e82ba' +source_hash = 'a1e21bb1f5ed468a279d69e3e2d84b9efed77f3a2de39edb3f2ef3ab143793a2' model_hash = '48d2531efe5409fb983ee7f3563399fae31c84ba23c738006f2a29337e4018ef' [crates.aws-sdk-securityhub] category = 'AwsSdk' version = '0.35.0' -source_hash = '731a1dd4ea84172ca5cca1a651a094384245949db143a391f989f88ab9b7fa6d' +source_hash = 'c775d148880d92909e12c6968d60342b4d617d923ba0096bb14da9c7275ec14b' model_hash = '9a62fa3cee3a038a03685d33ee9fde04af368aa1c16fc22dffd3a52a95e866b0' [crates.aws-sdk-securitylake] category = 'AwsSdk' version = '0.13.0' -source_hash = '3b38b727e815535cf357f030ea6c2a49bc83b41106a0b60e3dbe48849979d30f' +source_hash = '6d8826afbfde5cdc300cae51a088aebbb59801193033c9dfc2be2862a0632432' model_hash = '6d17d6fa1a40ae6cffebbf1dfc321ade20c241e0d4fb1af24fdce669ff76ac0e' [crates.aws-sdk-serverlessapplicationrepository] category = 'AwsSdk' version = '0.35.0' -source_hash = '014b7ad155c63c9f11d13c2a421d08e10137c2d3c846e09fbccb6769fa242605' +source_hash = 'eea4048f1f557e1d85758c449816bf8725f9705c0f5eb3a673b889abc065a1ef' model_hash = '822f44c97fdfaa85c3ee6febd57426ef08199ee9e623b5aeaee154705bea5e9c' [crates.aws-sdk-servicecatalog] category = 'AwsSdk' version = '0.35.0' -source_hash = '267063fe84ed7860a5b8439073ef73748a11e0c1a40f42fb693f0fa3b0975c0a' +source_hash = 'f7e7312b081075fbe3a463e77a82f8b47f5560f06939bdd95da4023744c9b862' model_hash = 'da138db16cbb4f04bbe6e4c4c47b85fb286457f9e21894afa7914d2889fff285' [crates.aws-sdk-servicecatalogappregistry] category = 'AwsSdk' version = '0.35.0' -source_hash = '1de40e1f5d31c5d0f7cc74e309e6fe2c6f92b7304aecd54a105b883e85238c89' +source_hash = '32c0f16506301a4a47f1dcc85a049794cca7b7249d4a9e54de9ee3099754f3d7' model_hash = '37de296b51bcbe3a121c19033c686760ed61b85f636fd0a4e629a8f5c17f8a3f' [crates.aws-sdk-servicediscovery] category = 'AwsSdk' version = '0.35.0' -source_hash = '75e5bd0991285ab3af2de66924c3da46553f82721a53301d7be4db761354cd91' +source_hash = '57e1748bd484b6e89bca5f66515d2117c23e71392bc21d0b9c4946c9eb8b3693' model_hash = '30acf25612d9e2274c18fe37524efb8ddd2d2681d5dc95db3d8707c4230dfc63' [crates.aws-sdk-servicequotas] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd2c607de1b70395c7f868050d9b925076c27d6b9cb035a4c3ceeb00af0822d82' +source_hash = 'f7f0b7f1c6b42f3cca5c276de31fffeb8183befee58b85ed2d398246b5548706' model_hash = '13b9bfd192ebff6750f9102a2a9dbae7ef3727afff2326c2b21a547e96d91285' [crates.aws-sdk-ses] category = 'AwsSdk' version = '0.35.0' -source_hash = '32b1c3f1a07218f3c7f8bc9b3e98054384c3f9e0101fb2daf1fc7cc5fee4d066' +source_hash = 'a321fa9c3ac43b89e2cdc476b0e8ee55764bbcef035552eed7a784ad09bf487a' model_hash = '22978d391f3d0cfec8d0df7a9eccd555313bb45e3f5473b7a65e00053828852b' [crates.aws-sdk-sesv2] category = 'AwsSdk' version = '0.35.0' -source_hash = '0c6249b1a227f796e9f0ea54269c863f0fe4fce494ecb8cec95f6731fe8b655e' +source_hash = '8d32adfdfd2409f31cd40fb30fc8bbe2f2c4e6e11a861a74cc5836eab50f0626' model_hash = '8624b480bd9c4475f3b1c1c304545f775ee8bd59ade45f1cfcde4008c53df390' [crates.aws-sdk-sfn] category = 'AwsSdk' version = '0.35.0' -source_hash = '301c5668e50b1f64e8f7038873b3f6d3f7640ae8eb126ae0bd928e5bc3d97130' +source_hash = '01418fe41d404de1deffa02bde1988272a357bfe7a5d1ef092cfef7f55876c88' model_hash = '0bcf1b9b0e5120d513ea062355cc1cd3d622a992211e433e7b56f050948c21c9' [crates.aws-sdk-shield] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ca119542a925d0105541de81a36c35fffb39a3d0e02445cc64f5e87f47bd0afb' +source_hash = '713ac24e5f2301e296b96dc8f9a8ed30a4b15f6077397bf4034dadd5deb5d6cc' model_hash = 'a5fb86ec012001f4b5213f806f10e170354a0921207a8e173d7c8f1f4bb9c8b5' [crates.aws-sdk-signer] category = 'AwsSdk' version = '0.35.0' -source_hash = '750b1be7f0234f7b4ed5747172c38c8fd7e6590adb036e719d6b4a74c88b6c3c' +source_hash = 'a8a44f85b04897438ea0d7b626317856bf8f11d732eedbf1da6f9b48c6137da0' model_hash = 'edac7376a5d10e8f1e8130e467533f289b048eb6848a2050cecba8caa8943976' [crates.aws-sdk-simspaceweaver] category = 'AwsSdk' version = '0.13.0' -source_hash = '5c1ccd91f1577c60b0af04a2b84baa69b6f3b2d55f5d251b6a04ae6bd553a7ac' +source_hash = 'ebd377e1fd79908b35169c8576e1eb271e52456b8cd48848f58c01970a87d14a' model_hash = '533e82156505729b8d145bb443d469e37968adce23515d1a90ee2a597bd5447d' [crates.aws-sdk-sms] category = 'AwsSdk' version = '0.35.0' -source_hash = 'cc7d3c4f3a87fcc0a6090cbdeb7d0b4d6a47f7aceb523d1adf5c4c7829f47560' +source_hash = 'ad4b56b61dbf29134a74da5c57bcaed0c76129d8c96a0fe30b4d9eb38142c7d0' model_hash = 'ca2de1f7c9f67ac9aa065738dc673137ca4b2e8e86373c413da2a41c7f42f232' [crates.aws-sdk-snowball] category = 'AwsSdk' version = '0.35.0' -source_hash = '5ab1c1eb8a810b17e2e5ab112e0251c2111d48fcfbfa2e608d3c858c1804a0ab' +source_hash = '07b00c8e2654e8d14e7d0208da8a75cf38c8db467488864e42a18735096975e5' model_hash = '7c2e520512e03ab2db256fe574c2c08d4aa299403359f2e71f9f43f6b73b93b2' [crates.aws-sdk-snowdevicemanagement] category = 'AwsSdk' version = '0.35.0' -source_hash = '11225d1844d30644d39ab6de3254eaf10342a4270979d1179e162f0a7808e4f3' +source_hash = '749c0adfa2b6b23de53ce353777438e2c816dc504cbbaa64a3b2497f7ef6b100' model_hash = '171cb2c324ef8098f094220d7fe04469ccaadb534fa5658d8b9d7a816252815a' [crates.aws-sdk-sns] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ff70766fc468306cefb1e6334e45d77a1216b464f66f42adfb17eb6397184af5' +source_hash = '7fc28eaca78d6d37cd9ab754ab3a1d660ca8b82a180fb3c22029c7d2dbda5439' model_hash = 'aeeb86b63b2aa88c10f0516945c5ec2a1c736a434e8c88eba876a11b2f0f900d' [crates.aws-sdk-sqs] category = 'AwsSdk' version = '0.35.0' -source_hash = '8726b4fd0e18ca6609be7b3d434d438e82add62d36d6f59ec577aecb1edf3205' +source_hash = '5b3a1638828e33d73bddaf71988ea841d7d0da122129aa4e5f65d9a5b69dce36' model_hash = 'e3b289d9bdbdceec40a04f6b398a0e63516741ce787c7c20f3e3fe8c371e58a9' [crates.aws-sdk-ssm] category = 'AwsSdk' version = '0.35.0' -source_hash = '5b87cc3a02353b3f7bf5cd4152b66666b5459d28ea383326f5f42863e4bdd712' +source_hash = 'e9cb0465aac6867ce09eac1edf567ec0f3fc8352f8668821c62ce3d084579673' model_hash = '33dd4a334a01550c918b7b68b7a8124e27c08945f69b103412182f01242b1aa5' [crates.aws-sdk-ssmcontacts] category = 'AwsSdk' version = '0.35.0' -source_hash = '8cfe44cc2ef80c0ad6a1010e095ccd2cf7d2698523ac1f16516bc00ed3f37e7a' +source_hash = '9a051a0bd2ea3a8ddfff5877f90db128a9768c4b816d1896aaf4a19cd59e04c9' model_hash = '7917a0daad67c7ac35a49446f890181b3f303a4c536b7b141a03060795eb101f' [crates.aws-sdk-ssmincidents] category = 'AwsSdk' version = '0.35.0' -source_hash = '138363bbbc782e094cb4d9a8fafb28cf30bf5c8aa9aa73c57ec3dec16235f813' +source_hash = '2eaa3c3a59fefb03f66381a406a01f39bef48187118b35857ea1e22960dc7961' model_hash = 'da1f53e6e27496b6fd166f7582c3c10003d4062769e03b5551ecfdb7997ed5e9' [crates.aws-sdk-ssmsap] category = 'AwsSdk' version = '0.13.0' -source_hash = '2775f1c0f81cdce96e963b2d767778ce75e9bd9ed8d8375b1f49924e223dfd8f' +source_hash = 'e094ea0c0407307291682a4e4294262667e08eb63394dca90b95619433416524' model_hash = 'a94c75320672b18074add0252be1959ec86b7c0d4616d632816cdcf9f7939878' [crates.aws-sdk-sso] category = 'AwsSdk' version = '0.35.0' -source_hash = '27ff0df5edaf2c1bf36c85ee2a1bb196ccd0e6f5ee417fb2973e8411d6d7cddd' +source_hash = '59c603b4fc9f7487de4830ab863ac4163b5d252c497f082dc3d518a0fccf394d' model_hash = '9e59beae18125c2c7ec98cb3e1c1d88a68f2dd71b43249a780704b4ae0fab357' [crates.aws-sdk-ssoadmin] category = 'AwsSdk' version = '0.35.0' -source_hash = 'c7e1219ead8ff40d5e3645abf3b66c83800fd6cc19ac24b425b20144a1777839' +source_hash = '4290e13d69727cb55dc1cede4a68c93824da1e34e7f6d4eaf02aae61f727898a' model_hash = 'a7fe7ad1317132fe0ca70ea2b28ec3878da86608b91c6aaa152931c4d894f411' [crates.aws-sdk-ssooidc] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f8ba234fb0dda865e281a435e3411acdc16fb7a80ed8a16d334597f53c7e487a' +source_hash = '088d7c28501dd091b1179ecca93b99b56cd00288279f8492784763f9d17b4e6c' model_hash = 'a709dbe9aa130874459072a1ee36c3461b8113a75efe3785a673a4a1400323c8' [crates.aws-sdk-storagegateway] category = 'AwsSdk' version = '0.35.0' -source_hash = '38663a068be76033e84c1ca5a8ef6bbb5438975c3f58571c461d7ed96651fa4a' +source_hash = 'cf8ee2df785f8fba24c6050f29d48806b1854bd010bba523a59a975711629f18' model_hash = '66d656b1d8028312c81f1d55a9a7943f1c596efd36196c38932bfc9566d5f6d0' [crates.aws-sdk-sts] category = 'AwsSdk' version = '0.35.0' -source_hash = '964803a823cbfeec498a71eea457cb6233adbd624080a72350d272ecb8c0eb8b' +source_hash = '067308113fba6a1fa883e088a2640315b2e18522bf2bb982615b28d8b15eb612' model_hash = '4daf865fbb19724d8da1764804ec9d3df6d60371c4bfd4cabfca40c8bda614f4' [crates.aws-sdk-support] category = 'AwsSdk' version = '0.35.0' -source_hash = '206057185864541a67ede9e47ce06d186cfc053dc6d1e60c08c1e61492d9742e' +source_hash = '062f58ac8b95d5d2c607a65523e860217b4acd882e0f5919e15e63aadf2ad44a' model_hash = '17332e0d9b8cc1d20e3e816c18621ab70fbaa7f3629f66be5fe76e9966a41421' [crates.aws-sdk-supportapp] category = 'AwsSdk' version = '0.18.0' -source_hash = '616be6d1513e3d7ef05f02b81e08772d25d246eb993402ebaeaccc852c677967' +source_hash = '03b9d4abb6da261ec2c4593f488b9afda6fb4c6884a8493ac13359c85957fcdd' model_hash = '9c99c40c7f7afedcc9d6351198ddbe8ff1193e6b6abe1d6582612e046d4ae8da' [crates.aws-sdk-swf] category = 'AwsSdk' version = '0.35.0' -source_hash = '0198ce5d333d49d00cb00d6b9e6cae57f715fcd6bab1b9a6a4c94c9d846d7db3' +source_hash = '9e24c193dbe0b29665156ce4f772bc313bb7febb4b07a70962586b1b10fd5968' model_hash = '400f9ff11622646a623660e5e1cfa33aece171da53fd27fe2d8202b2d3ae531b' [crates.aws-sdk-synthetics] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd7a9cf26c6207857ad48a9d4e79de7b2ece31e468dbb19a01da1632ae5b4aa30' +source_hash = '91aa239a797853d522aaea467d5409c7238bec8dc0c1f92116b5fea9e4aebe9d' model_hash = '0d73091f6ab96111985988e6f726ebfe5861c37d443db368f8f16ffbadc402cd' [crates.aws-sdk-textract] category = 'AwsSdk' version = '0.35.0' -source_hash = '2e721e0b89ef5fc62f85fae472df094639b0b7d697ad5f842315e945230a691f' +source_hash = '46043b9f18efc9a23fe8b47726999df86d14b0465542a07a4b736dfb4e9afd76' model_hash = 'a53d78aba76a9e4ea3ea54db9720f8c1bf9a20b349516a5afce390bb40f55a9f' [crates.aws-sdk-timestreamquery] category = 'AwsSdk' version = '0.7.0' -source_hash = 'f6c0e337eb1c00b166618dc6d8348172c9edb032308f7b06bb2be30f5622f993' +source_hash = '74a161bafbef1a9780a277089df2777ec77d73e6bc760899b9e895484699d9ff' model_hash = '5da0125b16b35356c55344243bf75a6210e1e923a979f6a60312f74dc9106e03' [crates.aws-sdk-timestreamwrite] category = 'AwsSdk' version = '0.7.0' -source_hash = '539afd394f9416b1ddc6f49b40d5c119fb0090c3aff386c58b6dd8ff5aec4d24' +source_hash = 'f8480cb9eb1be2acf2bc95c5f6127432018029b6bffc8d1578513d954e2403dc' model_hash = 'a1f3262010b114c954ec3ebca471c6aff8b2957af4969be36e5ac081683a3c7e' [crates.aws-sdk-tnb] category = 'AwsSdk' version = '0.11.0' -source_hash = 'aeb788f73c3a859d7f1eb65d0be420618a491d6510746341a7f4c9510c87c561' +source_hash = 'c45f7eae3e7d92a7822790b2dc579ff6ec439f9d1e38eb9517c970117ff514cf' model_hash = '153626e8fb6b3863afd4b91cd157c8ca6d27db4513982a66221826d7c4417405' [crates.aws-sdk-transcribe] category = 'AwsSdk' version = '0.35.0' -source_hash = '0f670b2863c92e55a91b7e50504e7da44b8304c2eef09439ad38b2e8829a2a40' +source_hash = 'cb084dfef96a4db2f2b0e7167c0fcca6493ff8cd20a54c45f4d11245c38eb53b' model_hash = 'd6be2cac40cd927e330d9251b66d01a16feb42ac4e467a7799e2fe5a97d1d5c0' [crates.aws-sdk-transcribestreaming] category = 'AwsSdk' version = '0.35.0' -source_hash = 'e4f0d2ab80479b429e0bb59c82f2fc884136a92806463474b67a54e42d2c4485' +source_hash = '5c750e2d0df77273805c037fd30af5d80fc72e8f821b480b7fd48529c7b4e423' model_hash = '05649800aa6833ee5639f2dbec536ed420883d394c8c0072664e1b35389c6178' [crates.aws-sdk-transfer] category = 'AwsSdk' version = '0.35.0' -source_hash = 'af9d8213cdfb3d15805ecfb01421b23a872bcf58eab940d92173fcf2f33aa2ab' +source_hash = '46ed37f6d56c9586bf55f59c5478d1ce2cb42a46944d1bbcfe8588cb23748810' model_hash = '1bce54ff576e455f370caa2e647f1a8ccecfda014bd5013f6b306f235f3a9bfe' [crates.aws-sdk-translate] category = 'AwsSdk' version = '0.35.0' -source_hash = '028294edda6ab439e093ffd6067fad25b7b335af4d018c69afb523426afd0592' +source_hash = 'fa23c702869a73d625164c9345a1fd04aabe721c242e59c9f58ba6a3d87e0cfc' model_hash = '0dd014a1b4a9d2b22ce7dd4fc8c0745e603cbf5ec231ae9f0d687b512ba46057' [crates.aws-sdk-verifiedpermissions] category = 'AwsSdk' version = '0.7.0' -source_hash = '4d3cae2e9022fa30c919443c2f9dc7c3d048231dee1f58e8878f73fe49dd80c9' +source_hash = 'a39d81b361b83f4656f12e52477fd1780ab41ad6fafe91be52dce8549256569b' model_hash = '05c854e62bf2e3f468466e33e07d8d729e50d754210d61763f1f52c38f866432' [crates.aws-sdk-voiceid] category = 'AwsSdk' version = '0.35.0' -source_hash = '734d4668d73c68d0860726f41c9bae55a62f8fbaa2b9ad62057e9976c271aa76' +source_hash = '300c2a2dcdc34840a9282e6758c10c4f5d599359e366b2121c758a2cf45015fc' model_hash = 'babc302a2d66181ccf27747be08198131836d1c11d345693aaf744dc8963f667' [crates.aws-sdk-vpclattice] category = 'AwsSdk' version = '0.11.0' -source_hash = '18bf0be1315c5eefdea4d70bd365f84c8e86fd0e719c3b69066caffe5e259239' +source_hash = 'ba99639d569cb508bebe73df05b212ddad4041add7a92587c38e8e33bd362c48' model_hash = 'f5221c586cb7aa327f5a8c5942e5cb0d302ad672b4138a3fd08efca8bb5dd3de' [crates.aws-sdk-waf] category = 'AwsSdk' version = '0.35.0' -source_hash = '0d25db67d6434c7f298d8a7d5cd32400bff8bd62509328e6f08788d04a2918d0' +source_hash = '63983476890a366b14f24e7121504ba76ece799ed31839777de4182685e05e34' model_hash = 'fe9760a59b9f625d02d2da525d76dd9f1203e0ead84e38e317aa6ddda8687648' [crates.aws-sdk-wafregional] category = 'AwsSdk' version = '0.35.0' -source_hash = 'ea82c64d3089a8ea2741616f3a34e1edfc00234ed23a44853fb7c3c783df0034' +source_hash = '9acd412f1d12beaf3cd5d93ba47b9c4a2852f15a154c0ebca9803e552252785d' model_hash = '56869f15eb4277a7d7b350709d0fcee7899789b9f751f95c5e7e94fb94087038' [crates.aws-sdk-wafv2] category = 'AwsSdk' version = '0.35.0' -source_hash = 'd4f836178d82567bab0033b35dd0b93d59748d50571d70d48c8ffc3ef48c85bc' +source_hash = 'f7992d6029a3efbecf74ca4a4fbb2093863343c23ddb21aaeda7d912ab8dab24' model_hash = '239273e4f93d44aa2a365811d5e400a8cb32c61af4bcf7c979689d7b5207c263' [crates.aws-sdk-wellarchitected] category = 'AwsSdk' version = '0.35.0' -source_hash = '9aacb2a53834a81a24859b9d7107fcccf9eb66fdde09236a4a3f122ce097d70f' +source_hash = '7f2ad41446aae228684a07aecd19ba3ee6901a833de7788893d6b55305555ac8' model_hash = '5d0724494f4e421d1e381d50e448937c01bfa9fbd36b7f43d8110532be7c624d' [crates.aws-sdk-wisdom] category = 'AwsSdk' version = '0.35.0' -source_hash = '209cb37e32342f23ae0875fb5394fe4f08e92a0952a12616717bd439013dc6e4' +source_hash = '5c0ddcc1ccceebaad03277c13b7ce1dc6e76d209d3261c0201cf830fe8812712' model_hash = 'fae9e424b8f855c388271dbd2ef5a5e391d884d1eaa1e31e626037f61eb8a10f' [crates.aws-sdk-workdocs] category = 'AwsSdk' version = '0.35.0' -source_hash = 'eaf3955d45baf857991d0d76e32c30b290507640f9a9a776331d2bf1b9767332' +source_hash = '5d52ef1fe9927cd250add404d6d446a23608a8c737ba5e0259d2b0b6b58cd9c6' model_hash = '3089c7f60a3c27474e6d041d518345ba73f9cf14a14e0c48cc1d54e720cc4ac5' [crates.aws-sdk-worklink] category = 'AwsSdk' version = '0.35.0' -source_hash = '25fd8001d3580386214a02f783107353fcdc6fd1a9de0bf4942dcfe5e715f0a5' +source_hash = 'abc786e9f380024d1277c8e4960f49b227c7567b848c7e08a92167cd9a9281e5' model_hash = '564ce85651697fd253e7cd4570e94141faaad0ade1a55f88d39d9b87b1f4df54' [crates.aws-sdk-workmail] category = 'AwsSdk' version = '0.35.0' -source_hash = 'f1d0341fb476c4b1959137d26002752447182dc0431eb4f9c57467cd16d782c9' +source_hash = '59da8b0c8519242c0aea8a078fa9fe39d56cbc11b8ff9484ec5df48bd5313ee2' model_hash = '269012e20ea0de0e65f3b0e1b33bb1ec8ee344571e723132480608d6e0d04b5e' [crates.aws-sdk-workmailmessageflow] category = 'AwsSdk' version = '0.35.0' -source_hash = '1b2baa27a5a11fbaf8f0d92bd40a3ad6caf0abb31df8d99d24b56a6f03ac5052' +source_hash = '464a4b9ef1ead50524ee3f1b92d199b9f76c08a7f1e4ffa6fbe7ba4e19f8f1b1' model_hash = 'eab0659c4890363f26af020432f7d7c661fd228f3baeef3a52d77f80a1c13287' [crates.aws-sdk-workspaces] category = 'AwsSdk' version = '0.35.0' -source_hash = 'aeecd69252fff5f3c28d0c617adf69cac5035b5c4a15a399a540ef2e9e82781c' +source_hash = 'ad3495f428d08b6f7bf9a0b09a9c3346743efcd9f89cc2c4fb04c54725de4c25' model_hash = '2357dd2b609adf41fdec84d87fecd96925666e189014891c95520a74fe89c189' [crates.aws-sdk-workspacesweb] category = 'AwsSdk' version = '0.35.0' -source_hash = '30714ec0cd63c9e6cb11091082ed483042af859f251f449d6fab81f58c0806de' +source_hash = '43378accf3f134ea2004c143418d64b31f816b79523f75ab4055cb0c5fd74439' model_hash = '24989ad30e9105cc0b4e5ae4e5762fca86ff638e114b5bf7f260278a54a1050b' [crates.aws-sdk-xray] category = 'AwsSdk' version = '0.35.0' -source_hash = '384f72b4e1655a1df939cf614c84f806cf81ee2b5b9e943e15906e7bf60a6d6f' +source_hash = '73d571a6f597b9d428a7c965cabe83a4b90b5bf60b7c1ee7da45ff396188de28' model_hash = '25c4c2af8e9c134e34445bd47d23fc5f8a03662b3d89e4dc40d1762486069be3' [crates.aws-sig-auth] @@ -2212,7 +2212,7 @@ source_hash = '7e50546dc3a4bb59cb5c0cd6fe92c09d038ed5e78be4530ab662300150b2414e' [crates.aws-smithy-http] category = 'SmithyRuntime' version = '0.56.1' -source_hash = '7a2e0842d0b006696957de2495a5ef6406f4fed275c711c2c5962d52231358d6' +source_hash = '61b4f35f881f8cab6122e2832e3f2e8b684b5e2d12be76949407cceccc1284ad' [crates.aws-smithy-http-auth] category = 'SmithyRuntime' @@ -2252,7 +2252,7 @@ source_hash = '61b93c1d6bd65152917a336add1676ecdd2ce460556dd53775b8df30c451656b' [crates.aws-smithy-runtime] category = 'SmithyRuntime' version = '0.56.1' -source_hash = '60758e79f4f0805342b07b6dfac5e01d9104a7c4fd5fb24c9d98883444026f75' +source_hash = 'a0eba76155f6a6cee8bd2b86444f91c7d67fad70224ceac15ea3a04010071d7a' [crates.aws-smithy-runtime-api] category = 'SmithyRuntime'